home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / scribus-ng / plugins / barcode.ps next >
Encoding:
Text File  |  2009-03-15  |  225.6 KB  |  6,600 lines

  1. %!PS-Adobe-2.0
  2. %%Creator: Terry Burton
  3. %%DocumentPaperSizes: a4
  4. %%EndComments
  5.  
  6. % Barcode Writer in Pure PostScript - Version 2009-03-06
  7. % http://www.terryburton.co.uk/barcodewriter/
  8. %
  9. % Copyright (c) 2004-2009 Terry Burton
  10. %
  11. % Permission is hereby granted, free of charge, to any
  12. % person obtaining a copy of this software and associated
  13. % documentation files (the "Software"), to deal in the
  14. % Software without restriction, including without
  15. % limitation the rights to use, copy, modify, merge,
  16. % publish, distribute, sublicense, and/or sell copies of
  17. % the Software, and to permit persons to whom the Software
  18. % is furnished to do so, subject to the following
  19. % conditions:
  20. %
  21. % The above copyright notice and this permission notice
  22. % shall be included in all copies or substantial portions
  23. % of the Software.
  24. %
  25. % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  26. % KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  27. % THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  28. % PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  29. % THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  30. % DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  31. % CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  32. % CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  33. % IN THE SOFTWARE.
  34.  
  35. % Uncomment this next line to allow these procedure definitions to 
  36. % remain resident within a printer's PostScript virtual machine 
  37. % so that the barcode generation capability persists between jobs.
  38.  
  39. % serverdict begin 0 exitserver 
  40.  
  41. % --BEGIN TEMPLATE--
  42.  
  43. % --BEGIN RENDERER renlinear--
  44. /renlinear {
  45.  
  46.     1 dict begin          % Confine variables to local scope
  47.  
  48.     /args exch def   % We are given some arguments
  49.  
  50.     % Default options
  51.     /sbs [] def
  52.     /bhs [] def
  53.     /bbs [] def
  54.     /txt [] def
  55.     /barcolor (unset) def
  56.     /includetext false def
  57.     /textcolor (unset) def
  58.     /textxalign (unset) def
  59.     /textyalign (unset) def
  60.     /textfont (Courier) def
  61.     /textsize 10 def
  62.     /textxoffset 0 def
  63.     /textyoffset 0 def
  64.     /alttext () def
  65.     /bordercolor (unset) def
  66.     /backgroundcolor (unset) def
  67.     /inkspread 0.15 def
  68.     /width 0 def
  69.     /barratio 1 def
  70.     /spaceratio 1 def
  71.     /showborder false def
  72.     /borderleft 10 def
  73.     /borderright 10 def
  74.     /bordertop 1 def
  75.     /borderbottom 1 def
  76.     /borderwidth 0.5 def
  77.     /guardwhitespace false def
  78.     /guardleftpos 0 def
  79.     /guardleftypos 0 def
  80.     /guardrightpos 0 def
  81.     /guardrightypos 0 def
  82.     /guardwidth 6 def
  83.     /guardheight 7 def
  84.     
  85.     % Apply the renderer options and the user options
  86.     args {def} forall
  87.     opt {def} forall 
  88.  
  89.     /barcolor barcolor cvlit def
  90.     /textcolor textcolor cvlit def
  91.     /textxalign textxalign cvlit def
  92.     /textyalign textyalign cvlit def
  93.     /textfont textfont cvlit def
  94.     /textsize textsize cvr def
  95.     /textxoffset textxoffset cvr def
  96.     /textyoffset textyoffset cvr def
  97.     /alttext alttext cvlit def
  98.     /bordercolor bordercolor cvlit def
  99.     /backgroundcolor backgroundcolor cvlit def
  100.     /inkspread inkspread cvr def
  101.     /width width cvr def
  102.     /barratio barratio cvr def
  103.     /spaceratio spaceratio cvr def
  104.     /borderleft borderleft cvr def
  105.     /borderright borderright cvr def
  106.     /bordertop bordertop cvr def
  107.     /borderbottom borderbottom cvr def
  108.     /borderwidth borderwidth cvr def
  109.     /guardleftpos guardleftpos cvr def
  110.     /guardleftypos guardleftypos cvr def
  111.     /guardrightpos guardrightpos cvr def
  112.     /guardrightypos guardrightypos cvr def
  113.     /guardwidth guardwidth cvr def
  114.     /guardheight guardheight cvr def
  115.     
  116.     % Create bar elements and put them into the bars array
  117.     /bars sbs length 1 add 2 idiv array def
  118.     /x 0.00 def /maxh 0 def
  119.     0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
  120.         /i exch def
  121.         i 2 mod 0 eq {           % i is even
  122.             /d sbs i get barratio mul barratio sub 1 add def  % d=digit*r-r+1 
  123.             /h bhs i 2 idiv get 72 mul def  % Height from bhs
  124.             /c d 2 div x add def            % Centre of the bar = x + d/2
  125.             /y bbs i 2 idiv get 72 mul def  % Baseline from bbs
  126.             /w d inkspread sub def          % bar width = digit - inkspread
  127.             bars i 2 idiv [h c y w] put     % Add the bar entry
  128.             h maxh gt {/maxh h def} if
  129.         } {
  130.             /d sbs i get spaceratio mul spaceratio sub 1 add def  % d=digit*r-r+1 
  131.         } ifelse
  132.         /x x d add def  % x+=d
  133.     } for
  134.  
  135.     gsave
  136.  
  137.     currentpoint translate
  138.  
  139.     % Force symbol to given width
  140.     width 0 ne {
  141.         width 72 mul x div 1 scale
  142.     } if
  143.  
  144.     % Set RGB or CMYK color depending on length of given hex string
  145.     /setanycolor {
  146.         /anycolor exch def
  147.         anycolor length 6 eq {
  148.             (<      >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
  149.         } if
  150.         anycolor length 8 eq {
  151.             (<        >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
  152.         } if
  153.     } bind def
  154.  
  155.     % Display the border and background
  156.     newpath
  157.     borderleft neg borderbottom neg moveto
  158.     x borderleft add borderright add 0 rlineto
  159.     0 maxh borderbottom add bordertop add rlineto
  160.     x borderleft add borderright add neg 0 rlineto
  161.     0 maxh borderbottom add bordertop add neg rlineto    
  162.     closepath
  163.     backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if     
  164.     showborder {
  165.         gsave
  166.         bordercolor (unset) ne { bordercolor setanycolor } if
  167.         borderwidth setlinewidth stroke
  168.         grestore
  169.     } if    
  170.    
  171.     % Display the bars for elements in the bars array
  172.     gsave
  173.     0 setlinecap
  174.     barcolor (unset) ne { barcolor setanycolor } if
  175.     bars {
  176.         {} forall
  177.         newpath setlinewidth moveto 0 exch rlineto stroke
  178.     } forall
  179.     grestore
  180.     
  181.     % Display the text for elements in the text array
  182.     textcolor (unset) ne { textcolor setanycolor } if
  183.     includetext {
  184.         textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
  185.             /s 0 def /f () def
  186.             txt {
  187.                 {} forall
  188.                 2 copy s ne exch f ne or {
  189.                     2 copy /s exch def /f exch def            
  190.                     exch findfont exch scalefont setfont          
  191.                 } {
  192.                     pop pop
  193.                 } ifelse
  194.                 moveto show
  195.             } forall
  196.         } {
  197.             textfont findfont textsize scalefont setfont
  198.             alttext () eq {
  199.                 /txt [ txt { 0 get {} forall } forall ] def
  200.                 /tstr txt length string def
  201.                 0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
  202.             } {
  203.                 /tstr alttext def
  204.             } ifelse
  205.             /textxpos textxoffset x tstr stringwidth pop sub 2 div add def
  206.             textxalign (left) eq { /textxpos textxoffset def } if
  207.             textxalign (right) eq { /textxpos x textxoffset sub tstr stringwidth pop sub def } if
  208.             textxalign (offleft) eq { /textxpos tstr stringwidth pop textxoffset add neg def } if
  209.             textxalign (offright) eq { /textxpos x textxoffset add def } if
  210.             /textypos textyoffset textsize add 3 sub neg def
  211.             textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
  212.             textyalign (center) eq { /textypos textyoffset maxh textsize 4 sub sub 2 div add def } if
  213.             textxpos textypos moveto tstr show
  214.         } ifelse
  215.     } if    
  216.  
  217.     % Display the guard elements
  218.     guardwhitespace {
  219.         0.75 setlinewidth
  220.         guardleftpos 0 ne {
  221.             newpath
  222.             guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
  223.             guardwidth neg guardheight -2 div rlineto
  224.             guardwidth guardheight -2 div rlineto
  225.             stroke            
  226.         } if
  227.         guardrightpos 0 ne {
  228.             newpath
  229.             guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
  230.             guardwidth guardheight -2 div rlineto
  231.             guardwidth neg guardheight -2 div rlineto
  232.             stroke            
  233.         } if
  234.     } if
  235.     
  236.     grestore
  237.     
  238.     end
  239.  
  240. } bind def
  241. % --END RENDERER renlinear--
  242.  
  243. % --BEGIN RENDERER renmatrix--
  244. /renmatrix {
  245.  
  246.     1 dict begin
  247.  
  248.     /args exch def
  249.  
  250.     % Default options
  251.     /width 1 def
  252.     /height 1 def
  253.     /color (unset) def
  254.     /backgroundcolor (unset) def
  255.  
  256.     % Apply the renderer options and the user options
  257.     args {def} forall
  258.     opt {def} forall
  259.  
  260.     /width width cvr def
  261.     /height height cvr def
  262.     /color color cvlit def
  263.     /backgroundcolor backgroundcolor cvlit def
  264.  
  265.     % Extend bitmap horizontally to an 8-bit boundary
  266.     /pixx8 pixx 8 div ceiling cvi 8 mul def
  267.     /pixs8 [ pixx8 pixy mul {0} repeat ] def
  268.     0 1 pixy 1 sub {
  269.         /i exch def
  270.         pixs8 pixx8 i mul pixs pixx i mul pixx getinterval putinterval
  271.     } for
  272.     /pixs pixs8 def
  273.  
  274.     % Convert bitmap into 8-bit sample string
  275.     /imgstr pixs length 8 idiv string def
  276.     0 1 pixs length 1 sub {
  277.         /i exch def
  278.         imgstr i 8 idiv 2 copy get 2 7 i 8 mod sub exp cvi pixs i get mul add put
  279.     } for
  280.  
  281.     % Set RGB or CMYK color depending on length of given hex string
  282.     /setanycolor {
  283.         /anycolor exch def
  284.         anycolor length 6 eq {
  285.             (<      >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
  286.         } if
  287.         anycolor length 8 eq {
  288.             (<        >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
  289.         } if
  290.     } bind def
  291.  
  292.     % Draw the image
  293.     gsave
  294.     currentpoint translate
  295.     72 width mul 72 height mul scale
  296.     .0001 .0001 moveto .9999 .0001 lineto .9999 .9999 lineto .0001 .9999 lineto closepath
  297.     backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if 
  298.     color (unset) ne { color setanycolor } if
  299.     pixx pixy true [ pixx 0 0 pixy neg 0 pixy ] {imgstr} imagemask
  300.     grestore
  301.  
  302.     end
  303.  
  304. } bind def
  305. % --END RENDERER renmatrix--
  306.  
  307. % --BEGIN RENDERER renmaximatrix--
  308. /renmaximatrix {
  309.  
  310.     1 dict begin
  311.  
  312.     /args exch def   % We are given some arguments
  313.  
  314.     % Apply the renderer options and the user options
  315.     args {def} forall
  316.     opt {def} forall
  317.  
  318.     gsave
  319.  
  320.     currentpoint translate
  321.  
  322.     2.4945 dup scale  % from 1pt to 1.88mm
  323.     0.5 0.5774 translate
  324.  
  325.     pixs {
  326.         dup 
  327.         /x exch 30 mod def 
  328.         /y exch 30 idiv def
  329.         y 2 mod 0 eq {x} {x 0.5 add} ifelse
  330.         32 y sub 0.8661 mul
  331.         moveto
  332.         0     0.5774 rmoveto
  333.         -0.5 -0.2887 rlineto
  334.         0    -0.5774 rlineto
  335.         0.5  -0.2887 rlineto
  336.         0.5   0.2887 rlineto
  337.         0     0.5774 rlineto
  338.         -0.5  0.2887 rlineto
  339.         closepath fill
  340.     } forall
  341.  
  342.     % Plot the locator symbol
  343.     newpath 14 13.8576 0.5774 0 360 arc closepath
  344.     14 13.8576 1.3359 360 0 arcn closepath fill
  345.     newpath 14 13.8576 2.1058 0 360 arc closepath
  346.     14 13.8576 2.8644 360 0 arcn closepath fill
  347.     newpath 14 13.8576 3.6229 0 360 arc closepath
  348.     14 13.8576 4.3814 360 0 arcn closepath fill
  349.  
  350.     grestore
  351.  
  352.     end
  353.  
  354. } bind def
  355. % --END RENDERER renmaximatrix--
  356.  
  357. % --BEGIN ENCODER ean5--
  358. % --DESC: EAN-5 (5 digit addon)
  359. % --EXAM: 90200
  360. % --EXOP: includetext guardwhitespace
  361. % --RNDR: renlinear
  362. /ean5 {
  363.  
  364.     1 dict begin
  365.  
  366.     /options exch def                   % We are given an option string
  367.     /barcode exch def                   % We are given a barcode string
  368.  
  369.     /dontdraw false def
  370.     /includetext false def              % Enable/disable text
  371.     /textfont /Helvetica def
  372.     /textsize 12 def
  373.     /textxoffset 0 def
  374.     /textyoffset (unset) def
  375.     /height 0.7 def    
  376.     
  377.     % Parse the input options
  378.     options type /stringtype eq {
  379.         1 dict begin
  380.         options {
  381.             token false eq {exit} if dup length string cvs (=) search
  382.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  383.         } loop
  384.         currentdict end /options exch def
  385.     } if
  386.     options {def} forall   
  387.  
  388.     /textfont textfont cvlit def
  389.     /textsize textsize cvr def
  390.     /height height cvr def
  391.     /textxoffset textxoffset cvr def
  392.     textyoffset (unset) eq {
  393.         /textyoffset height 72 mul 1 add def
  394.     } {
  395.         /textyoffset textyoffset cvr def
  396.     } ifelse
  397.     
  398.     % Create an array containing the character mappings
  399.     /encs
  400.     [ (3211) (2221) (2122) (1411) (1132)
  401.       (1231) (1114) (1312) (1213) (3112)
  402.       (112) (11)
  403.     ] def
  404.  
  405.     % Create a string of the available characters
  406.     /barchars (0123456789) def
  407.  
  408.     % Determine the mirror map based on mod 10 checksum
  409.     /mirrormaps
  410.     [ (11000) (10100) (10010) (10001) (01100)
  411.       (00110) (00011) (01010) (01001) (00101)
  412.     ] def
  413.     /checksum 0 def
  414.     0 1 4 {
  415.         /i exch def
  416.         /barchar barcode i get 48 sub def
  417.         i 2 mod 0 eq {
  418.             /checksum barchar 3 mul checksum add def
  419.         } {
  420.             /checksum barchar 9 mul checksum add def
  421.         } ifelse
  422.     } for
  423.     /checksum checksum 10 mod def
  424.     /mirrormap mirrormaps checksum get def
  425.  
  426.     /sbs 31 string def
  427.     /txt 5 array def
  428.    
  429.     0 1 4 {
  430.         /i exch def
  431.  
  432.         % Prefix with either a start character or separator character
  433.         i 0 eq {
  434.             sbs 0 encs 10 get putinterval
  435.         } {
  436.             sbs i 1 sub 6 mul 7 add encs 11 get putinterval
  437.         } ifelse
  438.  
  439.         % Lookup the encoding for the barcode character
  440.         barcode i 1 getinterval barchars exch search
  441.         pop                     % Discard true leaving pre
  442.         length /indx exch def   % indx is the length of pre
  443.         pop pop                 % Discard seek and post
  444.         /enc encs indx get def  % Get the indxth encoding
  445.         mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
  446.             /enclen enc length def
  447.             /revenc enclen string def
  448.             0 1 enclen 1 sub {
  449.                 /j exch def
  450.                 /char enc j get def
  451.                 revenc enclen j sub 1 sub char put
  452.             } for
  453.             /enc revenc def
  454.         } if
  455.         sbs i 6 mul 3 add enc putinterval   % Put encoded digit into sbs
  456.         txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textxoffset add textyoffset textfont textsize] put
  457.     } for
  458.  
  459.     % Return the arguments
  460.     <<
  461.     /ren (renlinear)
  462.     /sbs [sbs {48 sub} forall]
  463.     /bhs [16{height}repeat]
  464.     /bbs [16{0}repeat]
  465.     includetext {
  466.         /txt txt
  467.     } if
  468.     /opt options
  469.     /guardrightpos 10
  470.     /guardrightypos textyoffset 4 add
  471.     /bordertop 10
  472.     >>
  473.  
  474.     dontdraw not {//renlinear exec} if
  475.  
  476.     end
  477.  
  478. } bind def
  479. % --END ENCODER ean5--
  480.  
  481. % --BEGIN ENCODER ean2--
  482. % --DESC: EAN-2 (2 digit addon)
  483. % --EXAM: 05
  484. % --EXOP: includetext guardwhitespace
  485. % --RNDR: renlinear
  486. /ean2 {
  487.  
  488.     1 dict begin
  489.  
  490.     /options exch def                   % We are given an options string
  491.     /barcode exch def                   % We are given a barcode string
  492.  
  493.     /dontdraw false def
  494.     /includetext false def               % Enable/disable text
  495.     /textfont /Helvetica def
  496.     /textsize 12 def
  497.     /textxoffset 0 def
  498.     /textyoffset (unset) def
  499.     /height 0.7 def
  500.     
  501.     % Parse the input options
  502.     options type /stringtype eq {
  503.         1 dict begin
  504.         options {
  505.             token false eq {exit} if dup length string cvs (=) search
  506.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  507.         } loop
  508.         currentdict end /options exch def
  509.     } if
  510.     options {def} forall
  511.  
  512.     /textfont textfont cvlit def
  513.     /textsize textsize cvr def
  514.     /height height cvr def
  515.     /textxoffset textxoffset cvr def
  516.     textyoffset (unset) eq {
  517.         /textyoffset height 72 mul 1 add def
  518.     } {
  519.         /textyoffset textyoffset cvr def
  520.     } ifelse
  521.     
  522.     % Create an array containing the character mappings
  523.     /encs
  524.     [ (3211) (2221) (2122) (1411) (1132)
  525.       (1231) (1114) (1312) (1213) (3112)
  526.       (112) (11)
  527.     ] def
  528.  
  529.     % Create a string of the available characters
  530.     /barchars (0123456789) def
  531.  
  532.     % Determine the mirror map based on mod 4 checksum
  533.     /mirrormap [(00) (01) (10) (11)] barcode 0 2 getinterval cvi 4 mod get def
  534.  
  535.     /sbs 13 string def
  536.     /txt 2 array def
  537.     
  538.     0 1 1 {
  539.         /i exch def
  540.  
  541.         % Prefix with either a start character or separator character
  542.         i 0 eq {
  543.             sbs 0 encs 10 get putinterval
  544.         } {
  545.             sbs i 1 sub 6 mul 7 add encs 11 get putinterval
  546.         } ifelse
  547.  
  548.         % Lookup the encoding for the barcode character
  549.         barcode i 1 getinterval barchars exch search
  550.         pop                     % Discard true leaving pre
  551.         length /indx exch def   % indx is the length of pre
  552.         pop pop                 % Discard seek and post
  553.         /enc encs indx get def  % Get the indxth encoding
  554.         mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap    
  555.             /enclen enc length def
  556.             /revenc enclen string def
  557.             0 1 enclen 1 sub {
  558.                 /j exch def
  559.                 /char enc j get def
  560.                 revenc enclen j sub 1 sub char put
  561.             } for
  562.             /enc revenc def
  563.         } if
  564.         sbs i 6 mul 3 add enc putinterval   % Put encoded digit into sbs
  565.         txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textxoffset add textyoffset textfont textsize] put
  566.     } for
  567.  
  568.     % Return the arguments
  569.     <<
  570.     /ren (renlinear)
  571.     /sbs [sbs {48 sub} forall]
  572.     /bhs [12{height}repeat]
  573.     /bbs [12{0}repeat]
  574.     includetext {
  575.         /txt txt
  576.     } if
  577.     /opt options
  578.     /guardrightpos 10
  579.     /guardrightypos textyoffset 4 add
  580.     /bordertop 10
  581.     >>
  582.  
  583.     dontdraw not {//renlinear exec} if
  584.  
  585.     end
  586.  
  587. } bind def
  588. % --END ENCODER ean2--
  589.  
  590. % --BEGIN ENCODER ean13--
  591. % --SUGGESTS ean5 ean2--
  592. % --DESC: EAN-13
  593. % --EXAM: 977147396801
  594. % --EXOP: includetext guardwhitespace
  595. % --RNDR: renlinear
  596. /ean13 {
  597.  
  598.     1 dict begin
  599.  
  600.     /options exch def                  % We are given an option string
  601.     /barcode exch def                  % We are given a barcode string
  602.  
  603.     /dontdraw false def
  604.     /includetext false def             % Enable/disable text
  605.     /textfont /Helvetica def
  606.     /textsize 12 def
  607.     /textyoffset -4 def
  608.     /height 1 def
  609.     /addongap 12 def
  610.  
  611.     % Parse the input options, either a string or a dict
  612.     options type /stringtype eq {
  613.         1 dict begin
  614.         options {
  615.             token false eq {exit} if dup length string cvs (=) search
  616.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  617.         } loop
  618.         currentdict end /options exch def
  619.     } if
  620.     options {def} forall
  621.  
  622.     /textfont textfont cvlit def
  623.     /textsize textsize cvr def
  624.     /textyoffset textyoffset cvr def
  625.     /height height cvr def
  626.     /addongap addongap cvr def   
  627.  
  628.     % Split off the addon
  629.     barcode ( ) search {
  630.         /barcode exch def
  631.         pop
  632.         /addon exch def
  633.     } {
  634.         pop
  635.         /addon () def
  636.     } ifelse
  637.  
  638.     % Add checksum digit
  639.     /pad 13 string def
  640.     /checksum 0 def
  641.     0 1 11 {
  642.         /i exch def
  643.         /barchar barcode i get 48 sub def
  644.         i 2 mod 0 eq {
  645.             /checksum barchar checksum add def
  646.         } {
  647.             /checksum barchar 3 mul checksum add def
  648.         } ifelse
  649.     } for
  650.     /checksum 10 checksum 10 mod sub 10 mod def
  651.     pad 0 barcode putinterval       % Add barcode to the start of the pad
  652.     pad 12 checksum 48 add put      % Put ascii for checksum at end of pad
  653.     /barcode pad def
  654.  
  655.     % Create an array containing the character mappings
  656.     /encs
  657.     [ (3211) (2221) (2122) (1411) (1132)
  658.       (1231) (1114) (1312) (1213) (3112)
  659.       (111) (11111) (111)
  660.     ] def
  661.  
  662.     % Create a string of the available characters
  663.     /barchars (0123456789) def
  664.  
  665.     % Digits to mirror on left side
  666.     /mirrormaps
  667.     [ (000000) (001011) (001101) (001110) (010011)
  668.       (011001) (011100) (010101) (010110) (011010)
  669.     ] def
  670.  
  671.     /sbs 59 string def
  672.     /txt 13 array def
  673.   
  674.     % Put the start character
  675.     sbs 0 encs 10 get putinterval
  676.  
  677.     % First digit - determine mirrormap by this and show before guard bars
  678.     /mirrormap mirrormaps barcode 0 get 48 sub get def
  679.     txt 0 [barcode 0 1 getinterval -10 textyoffset textfont textsize] put
  680.  
  681.     % Left side - performs mirroring
  682.     1 1 6 {
  683.         % Lookup the encoding for the each barcode character
  684.         /i exch def
  685.         barcode i 1 getinterval barchars exch search
  686.         pop                            % Discard true leaving pre
  687.         length /indx exch def          % indx is the length of pre
  688.         pop pop                        % Discard seek and post
  689.         /enc encs indx get def         % Get the indxth encoding
  690.         mirrormap i 1 sub get 49 eq {   % Reverse enc if 1 in this position in mirrormap
  691.             /enclen enc length def
  692.             /revenc enclen string def
  693.             0 1 enclen 1 sub {
  694.                 /j exch def
  695.                 /char enc j get def
  696.                 revenc enclen j sub 1 sub char put
  697.             } for
  698.             /enc revenc def
  699.         } if
  700.         sbs i 1 sub 4 mul 3 add enc putinterval   % Put encoded digit into sbs
  701.         txt i [barcode i 1 getinterval i 1 sub 7 mul 4 add textyoffset textfont textsize] put
  702.     } for
  703.  
  704.     % Put the middle character
  705.     sbs 7 1 sub 4 mul 3 add encs 11 get putinterval
  706.  
  707.     % Right side
  708.     7 1 12 {
  709.         % Lookup the encoding for the each barcode character
  710.         /i exch def
  711.         barcode i 1 getinterval barchars exch search
  712.         pop                            % Discard true leaving pre
  713.         length /indx exch def          % indx is the length of pre
  714.         pop pop                        % Discard seek and post
  715.         /enc encs indx get def         % Get the indxth encoding
  716.         sbs i 1 sub 4 mul 8 add enc putinterval  % Put encoded digit into sbs
  717.         txt i [barcode i 1 getinterval i 1 sub 7 mul 8 add textyoffset textfont textsize] put
  718.     } for
  719.  
  720.     % Put the end character
  721.     sbs 56 encs 12 get putinterval
  722.  
  723.     /sbs [sbs {48 sub} forall] def
  724.     includetext {
  725.         /bhs [height height 12{height .075 sub}repeat height height 12{height .075 sub}repeat height height] def
  726.         /bbs [0 0 12{.075}repeat 0 0 12{.075}repeat 0 0] def
  727.     } {
  728.         /bhs [30{height}repeat] def
  729.         /bbs [30{0}repeat] def
  730.         /txt [] def
  731.     } ifelse
  732.     /guardrightypos 0 def
  733.  
  734.     % Append the addon
  735.     addon () ne {
  736.         /addopts <<
  737.             /dontdraw true
  738.             /includetext true
  739.             /height height 0.15 sub
  740.             /textxoffset 95 addongap add
  741.         >> def
  742.         addon length 2 eq {addon addopts //ean2 exec} if
  743.         addon length 5 eq {addon addopts //ean5 exec} if
  744.         /addcode exch def
  745.         /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
  746.         /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
  747.         /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
  748.         /txt [txt aload pop addcode (txt) get aload pop] def
  749.         /guardrightypos height 72 mul 6 sub def
  750.     } if 
  751.    
  752.     % Return the arguments
  753.     <<
  754.     /ren (renlinear)
  755.     /sbs sbs
  756.     /bhs bhs
  757.     /bbs bbs
  758.     /txt txt
  759.     /opt options
  760.     /guardrightpos 10
  761.     /guardrightypos guardrightypos
  762.     /borderbottom 5
  763.     >>
  764.  
  765.     dontdraw not {//renlinear exec} if
  766.  
  767.     end
  768.  
  769. } bind def
  770. % --END ENCODER ean13--
  771.  
  772. % --BEGIN ENCODER ean8--
  773. % --SUGGESTS ean5 ean2--
  774. % --DESC: EAN-8
  775. % --EXAM: 01335583
  776. % --EXOP: includetext guardwhitespace height=0.5
  777. % --RNDR: renlinear
  778. /ean8 {
  779.  
  780.     1 dict begin
  781.  
  782.     /options exch def                  % We are given an option string
  783.     /barcode exch def                  % We are given a barcode string
  784.  
  785.     /dontdraw false def
  786.     /includetext false def              % Enable/disable text
  787.     /textfont /Helvetica def
  788.     /textsize 12 def
  789.     /textyoffset -4 def
  790.     /height 1 def
  791.     /addongap 12 def
  792.     
  793.     % Parse the input options, either a string or a dict
  794.     options type /stringtype eq {
  795.         1 dict begin
  796.         options {
  797.             token false eq {exit} if dup length string cvs (=) search
  798.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  799.         } loop
  800.         currentdict end /options exch def
  801.     } if
  802.     options {def} forall
  803.    
  804.     /textfont textfont cvlit def
  805.     /textsize textsize cvr def
  806.     /textyoffset textyoffset cvr def
  807.     /height height cvr def
  808.     /addongap addongap cvr def   
  809.  
  810.     % Split off the addon
  811.     barcode ( ) search {
  812.         /barcode exch def
  813.         pop
  814.         /addon exch def
  815.     } {
  816.         pop
  817.         /addon () def
  818.     } ifelse
  819.  
  820.     % Create an array containing the character mappings
  821.     /encs
  822.     [ (3211) (2221) (2122) (1411) (1132)
  823.       (1231) (1114) (1312) (1213) (3112)
  824.       (111) (11111) (111)
  825.     ] def
  826.  
  827.     % Create a string of the available characters
  828.     /barchars (0123456789) def
  829.  
  830.     /sbs 43 string def
  831.     /txt 8 array def
  832.     
  833.     % Put the start character
  834.     sbs 0 encs 10 get putinterval
  835.  
  836.     % Left side
  837.     0 1 3 {
  838.         % Lookup the encoding for the each barcode character
  839.         /i exch def
  840.         barcode i 1 getinterval barchars exch search
  841.         pop                                % Discard true leaving pre
  842.         length /indx exch def              % indx is the length of pre
  843.         pop pop                            % Discard seek and post
  844.         /enc encs indx get def             % Get the indxth encoding
  845.         sbs i 4 mul 3 add enc putinterval  % Put encoded digit into sbs
  846.         txt i [barcode i 1 getinterval i 7 mul 4 add textyoffset textfont textsize] put
  847.     } for
  848.  
  849.     % Put the middle character
  850.     sbs 4 4 mul 3 add encs 11 get putinterval
  851.  
  852.     % Right side
  853.     4 1 7 {
  854.         % Lookup the encoding for the each barcode character
  855.         /i exch def
  856.         barcode i 1 getinterval barchars exch search
  857.         pop                                % Discard true leaving pre
  858.         length /indx exch def              % indx is the length of pre
  859.         pop pop                            % Discard seek and post
  860.         /enc encs indx get def             % Get the indxth encoding
  861.         sbs i 4 mul 8 add enc putinterval  % Put encoded digit into sbs
  862.         txt i [barcode i 1 getinterval i 7 mul 8 add textyoffset textfont textsize] put
  863.     } for
  864.  
  865.     % Put the end character
  866.     sbs 40 encs 12 get putinterval
  867.  
  868.     /sbs [sbs {48 sub} forall] def
  869.     includetext {
  870.         /bhs [height height 8{height .075 sub}repeat height height 8{height .075 sub}repeat height height] def
  871.         /bbs [0 0 8{.075}repeat 0 0 8{.075}repeat 0 0] def
  872.     } {
  873.         /bhs [22{height}repeat]
  874.         /bbs [22{0}repeat]
  875.         /txt [] def
  876.     } ifelse
  877.     /guardrightypos 0 def
  878.  
  879.     % Append the addon
  880.     addon () ne {
  881.         /addopts <<
  882.             /dontdraw true
  883.             /includetext true
  884.             /height height 0.15 sub
  885.             /textxoffset 67 addongap add
  886.         >> def
  887.         addon length 2 eq {addon addopts //ean2 exec} if
  888.         addon length 5 eq {addon addopts //ean5 exec} if
  889.         /addcode exch def
  890.         /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
  891.         /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
  892.         /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
  893.         /txt [txt aload pop addcode (txt) get aload pop] def
  894.         /guardrightypos height 72 mul 6 sub def
  895.     } if 
  896.  
  897.     % Return the arguments
  898.     <<
  899.     /ren (renlinear)
  900.     /sbs sbs
  901.     /bhs bhs
  902.     /bbs bbs
  903.     /txt txt
  904.     /opt options
  905.     /guardleftpos 10
  906.     /guardrightpos 10
  907.     /guardrightypos guardrightypos
  908.     /borderbottom 5
  909.     >>
  910.  
  911.     dontdraw not {//renlinear exec} if
  912.  
  913.     end
  914.  
  915. } bind def
  916. % --END ENCODER ean8--
  917.  
  918. % --BEGIN ENCODER upca--
  919. % --SUGGESTS ean5 ean2--
  920. % --DESC: UPC-A
  921. % --EXAM: 78858101497
  922. % --EXOP: includetext
  923. % --RNDR: renlinear
  924. /upca {
  925.  
  926.     1 dict begin
  927.  
  928.     /options exch def
  929.     /barcode exch def             % We are given a barcode string
  930.  
  931.     /dontdraw false def
  932.     /includetext false def         % Enable/disable text
  933.     /textfont /Helvetica def
  934.     /textsize 12 def
  935.     /textyoffset -4 def
  936.     /height 1 def 
  937.     /addongap 12 def
  938.  
  939.     % Parse the input options
  940.     options type /stringtype eq {
  941.         1 dict begin
  942.         options {
  943.             token false eq {exit} if dup length string cvs (=) search
  944.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  945.         } loop
  946.         currentdict end /options exch def
  947.     } if
  948.     options {def} forall    
  949.  
  950.     /textfont textfont cvlit def
  951.     /textsize textsize cvr def
  952.     /textyoffset textyoffset cvr def
  953.     /height height cvr def
  954.     /addongap addongap cvr def
  955.    
  956.     % Split off the addon
  957.     barcode ( ) search {
  958.         /barcode exch def
  959.         pop
  960.         /addon exch def
  961.     } {
  962.         pop
  963.         /addon () def
  964.     } ifelse
  965.  
  966.     % Add checksum digit to barcode
  967.     /pad 12 string def   % Create pad one bigger than barcode
  968.     /checksum 0 def
  969.     0 1 10 {
  970.         /i exch def
  971.         /barchar barcode i get 48 sub def
  972.         i 2 mod 0 ne {
  973.             /checksum checksum barchar add def
  974.         } {
  975.             /checksum checksum barchar 3 mul add def
  976.         } ifelse
  977.     } for
  978.     /checksum 10 checksum 10 mod sub 10 mod def
  979.     pad 0 barcode putinterval       % Add barcode to the start of the pad
  980.     pad 11 checksum 48 add put      % Put ascii for checksum at end of pad
  981.     /barcode pad def
  982.  
  983.     % Create an array containing the character mappings
  984.     /encs
  985.     [ (3211) (2221) (2122) (1411) (1132)
  986.       (1231) (1114) (1312) (1213) (3112)
  987.       (111) (11111) (111)
  988.     ] def
  989.  
  990.     % Create a string of the available characters
  991.     /barchars (0123456789) def
  992.  
  993.     /sbs 59 string def
  994.     /txt 12 array def
  995.  
  996.     % Put the start character
  997.     sbs 0 encs 10 get putinterval
  998.  
  999.     % Left side
  1000.     0 1 5 {
  1001.         % Lookup the encoding for the each barcode character
  1002.         /i exch def
  1003.         barcode i 1 getinterval barchars exch search
  1004.         pop                                % Discard true leaving pre
  1005.         length /indx exch def              % indx is the length of pre
  1006.         pop pop                            % Discard seek and post
  1007.         /enc encs indx get def             % Get the indxth encoding
  1008.         sbs i 4 mul 3 add enc putinterval  % Put encoded digit into sbs
  1009.         i 0 eq {      % First digit is before the guard bars
  1010.             txt 0 [barcode 0 1 getinterval -7 textyoffset textfont textsize 2 sub] put
  1011.         } {
  1012.             txt i [barcode i 1 getinterval i 7 mul 4 add textyoffset textfont textsize] put
  1013.         } ifelse
  1014.     } for
  1015.  
  1016.     % Put the middle character
  1017.     sbs 6 4 mul 3 add encs 11 get putinterval
  1018.  
  1019.     % Right side
  1020.     6 1 11 {
  1021.         % Lookup the encoding for the each barcode character
  1022.         /i exch def
  1023.         barcode i 1 getinterval barchars exch search
  1024.         pop                                % Discard true leaving pre
  1025.         length /indx exch def              % indx is the length of pre
  1026.         pop pop                            % Discard seek and post
  1027.         /enc encs indx get def             % Get the indxth encoding
  1028.         sbs i 4 mul 8 add enc putinterval  % Put encoded digit into sbs
  1029.         i 11 eq {       % Last digit is after guard bars
  1030.             txt 11 [barcode 11 1 getinterval 96 textyoffset textfont textsize 2 sub] put
  1031.         } {
  1032.             txt i [barcode i 1 getinterval i 7 mul 8 add textyoffset textfont textsize] put
  1033.         } ifelse
  1034.     } for
  1035.  
  1036.     % Put the end character
  1037.     sbs 56 encs 12 get putinterval
  1038.  
  1039.     /sbs [sbs {48 sub} forall] def
  1040.     includetext {
  1041.         /bhs [4{height}repeat 10{height .075 sub}repeat height height 10{height .075 sub}repeat 4{height}repeat] def
  1042.         /bbs [0 0 0 0 10{.075}repeat 0 0 10{.075}repeat 0 0 0 0] def
  1043.     } {
  1044.         /bhs [30{height}repeat] def
  1045.         /bbs [30{0}repeat] def
  1046.         /txt [] def
  1047.     } ifelse
  1048.     /guardrightypos 0 def
  1049.  
  1050.     % Append the addon
  1051.     addon () ne {
  1052.         /addopts <<
  1053.             /dontdraw true
  1054.             /includetext true
  1055.             /height height 0.15 sub
  1056.             /textxoffset 95 addongap add
  1057.         >> def
  1058.         addon length 2 eq {addon addopts //ean2 exec} if
  1059.         addon length 5 eq {addon addopts //ean5 exec} if
  1060.         /addcode exch def
  1061.         /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
  1062.         /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
  1063.         /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
  1064.         /txt [txt aload pop addcode (txt) get aload pop] def
  1065.         /guardrightypos height 72 mul 6 sub def
  1066.     } if 
  1067.  
  1068.     % Return the arguments
  1069.     <<
  1070.     /ren (renlinear)
  1071.     /sbs sbs
  1072.     /bhs bhs
  1073.     /bbs bbs
  1074.     /txt txt
  1075.     /opt options
  1076.     /guardrightpos 10
  1077.     /guardrightypos guardrightypos
  1078.     /borderbottom 5
  1079.     >>
  1080.  
  1081.     dontdraw not {//renlinear exec} if
  1082.  
  1083.     end
  1084.  
  1085. } bind def
  1086. % --END ENCODER upca--
  1087.  
  1088. % --BEGIN ENCODER upce--
  1089. % --SUGGESTS ean5 ean2--
  1090. % --DESC: UPC-E
  1091. % --EXAM: 0123456
  1092. % --EXOP: includetext height=0.4
  1093. % --RNDR: renlinear
  1094. /upce {
  1095.  
  1096.     1 dict begin
  1097.  
  1098.     /options exch def                   % We are given an option string
  1099.     /barcode exch def                   % We are given a barcode string
  1100.  
  1101.     /dontdraw false def
  1102.     /includetext false def               % Enable/disable text
  1103.     /textfont /Helvetica def
  1104.     /textsize 12 def
  1105.     /textyoffset -4 def
  1106.     /height 1 def
  1107.     /addongap 12 def   
  1108.  
  1109.     % Parse the input options
  1110.     options type /stringtype eq {
  1111.         1 dict begin
  1112.         options {
  1113.             token false eq {exit} if dup length string cvs (=) search
  1114.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  1115.         } loop
  1116.         currentdict end /options exch def
  1117.     } if
  1118.     options {def} forall
  1119.  
  1120.     /textfont textfont cvlit def
  1121.     /textsize textsize cvr def
  1122.     /textyoffset textyoffset cvr def
  1123.     /height height cvr def
  1124.     /addongap addongap cvr def    
  1125.  
  1126.     % Split off the addon
  1127.     barcode ( ) search {
  1128.         /barcode exch def
  1129.         pop
  1130.         /addon exch def
  1131.     } {
  1132.         pop
  1133.         /addon () def
  1134.     } ifelse
  1135.  
  1136.     % Create an array containing the character mappings
  1137.     /encs
  1138.     [ (3211) (2221) (2122) (1411) (1132)
  1139.       (1231) (1114) (1312) (1213) (3112)
  1140.       (111) (111111)
  1141.     ] def
  1142.  
  1143.     % Create a string of the available characters
  1144.     /barchars (0123456789) def
  1145.  
  1146.     /mirrormaps
  1147.     [ (000111) (001011) (001101) (001110) (010011)
  1148.       (011001) (011100) (010101) (010110) (011010)
  1149.     ] def
  1150.  
  1151.     % Derive the equivalent UPC-A for its checksum
  1152.     /upcacode (00000000000) 11 string copy def
  1153.     barcode 6 get 48 sub 2 le {
  1154.         upcacode 1 barcode 1 2 getinterval putinterval
  1155.         upcacode 3 barcode 6 1 getinterval putinterval
  1156.         upcacode 8 barcode 3 3 getinterval putinterval
  1157.     } if
  1158.     barcode 6 get 48 sub 3 eq {
  1159.         upcacode 1 barcode 1 3 getinterval putinterval
  1160.         upcacode 9 barcode 4 2 getinterval putinterval
  1161.     } if
  1162.     barcode 6 get 48 sub 4 eq {
  1163.         upcacode 1 barcode 1 4 getinterval putinterval
  1164.         upcacode 10 barcode 5 1 getinterval putinterval
  1165.     } if
  1166.     barcode 6 get 48 sub 5 ge {
  1167.         upcacode 1 barcode 1 5 getinterval putinterval
  1168.         upcacode 10 barcode 6 1 getinterval putinterval
  1169.     } if
  1170.     /checksum 0 def
  1171.     0 1 10 {
  1172.        /i exch def
  1173.        /barchar upcacode i get 48 sub def
  1174.        i 2 mod 0 ne {
  1175.            /checksum checksum barchar add def
  1176.        } {
  1177.            /checksum checksum barchar 3 mul add def
  1178.        } ifelse
  1179.     } for
  1180.     /checksum 10 checksum 10 mod sub 10 mod def
  1181.     /pad 8 string def
  1182.     pad 0 barcode putinterval       % Add barcode to the start of the pad
  1183.     pad 7 checksum 48 add put       % Put ascii for checksum at end of pad
  1184.     /barcode pad def
  1185.     /txt 8 array def
  1186.     txt 0 [barcode 0 1 getinterval -7 textyoffset textfont textsize 2 sub] put
  1187.  
  1188.     % Determine the mirror map based on checksum
  1189.     /mirrormap mirrormaps checksum get def
  1190.  
  1191.     % Invert the mirrormap if we are using a non-zero number system
  1192.     barcode 0 get 48 eq {
  1193.         /invt mirrormap length string def
  1194.         0 1 mirrormap length 1 sub {
  1195.             /i exch def
  1196.             mirrormap i get 48 eq {
  1197.                 invt i 49 put
  1198.             } {
  1199.                 invt i 48 put
  1200.             } ifelse
  1201.         } for
  1202.         /mirrormap invt def
  1203.     } if
  1204.  
  1205.     /sbs 33 string def
  1206.  
  1207.     % Put the start character
  1208.     sbs 0 encs 10 get putinterval
  1209.  
  1210.     1 1 6 {
  1211.         /i exch def
  1212.         % Lookup the encoding for the each barcode character
  1213.         barcode i 1 getinterval barchars exch search
  1214.         pop                            % Discard true leaving pre
  1215.         length /indx exch def          % indx is the length of pre
  1216.         pop pop                        % Discard seek and post
  1217.         /enc encs indx get def         % Get the indxth encoding
  1218.         mirrormap i 1 sub get 49 eq {  % Reverse enc if 1 in this position in mirrormap        
  1219.             /enclen enc length def
  1220.             /revenc enclen string def
  1221.             0 1 enclen 1 sub {
  1222.                 /j exch def
  1223.                 /char enc j get def
  1224.                 revenc enclen j sub 1 sub char put
  1225.             } for
  1226.             /enc revenc def
  1227.         } if
  1228.         sbs i 1 sub 4 mul 3 add enc putinterval   % Put encoded digit into sbs
  1229.         txt i [barcode i 1 getinterval i 1 sub 7 mul 4 add textyoffset textfont textsize] put
  1230.     } for
  1231.  
  1232.     txt 7 [barcode 7 1 getinterval 6 7 mul 11 add textyoffset textfont textsize 2 sub] put
  1233.  
  1234.     % Put the end character
  1235.     sbs 27 encs 11 get putinterval
  1236.  
  1237.     /sbs [sbs {48 sub} forall] def
  1238.     includetext {
  1239.         /bhs [height height 12{height .075 sub}repeat height height height] def
  1240.         /bbs [0 0 12{.075}repeat 0 0 0] def
  1241.     } {
  1242.         /bhs [17{height}repeat] def
  1243.         /bbs [17{0}repeat] def
  1244.         /txt [] def
  1245.     } ifelse
  1246.     /guardrightypos 0 def
  1247.  
  1248.     % Append the addon
  1249.     addon () ne {
  1250.         /addopts <<
  1251.             /dontdraw true
  1252.             /includetext true
  1253.             /height height 0.15 sub
  1254.             /textxoffset 51 addongap add
  1255.         >> def
  1256.         addon length 2 eq {addon addopts //ean2 exec} if
  1257.         addon length 5 eq {addon addopts //ean5 exec} if
  1258.         /addcode exch def
  1259.         /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
  1260.         /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
  1261.         /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
  1262.         /txt [txt aload pop addcode (txt) get aload pop] def
  1263.         /guardrightypos height 72 mul 6 sub def
  1264.     } if
  1265.  
  1266.     % Return the arguments
  1267.     <<
  1268.     /ren (renlinear)
  1269.     /sbs sbs
  1270.     /bhs bhs
  1271.     /bbs bbs
  1272.     /txt txt
  1273.     /opt options
  1274.     /guardrightpos 10
  1275.     /guardrightypos guardrightypos
  1276.     /borderbottom 5
  1277.     >>
  1278.  
  1279.     dontdraw not {//renlinear exec} if
  1280.  
  1281.     end
  1282.  
  1283. } bind def
  1284. % --END ENCODER upce--
  1285.  
  1286. % --BEGIN ENCODER isbn--
  1287. % --REQUIRES ean13--
  1288. % --SUGGESTS ean5 ean2--
  1289. % --DESC: ISBN
  1290. % --EXAM: 978-1-56592-479 54495
  1291. % --EXOP: includetext guardwhitespace
  1292. % --RNDR: renlinear
  1293. /isbn {
  1294.  
  1295.     1 dict begin
  1296.  
  1297.     /options exch def      % We are given an options string
  1298.     /isbntxt exch def      % We are given the isbn text with dashes
  1299.  
  1300.     /dontdraw false def
  1301.     /includetext false def  % Enable/disable ISBN text
  1302.     /isbnfont /Courier def
  1303.     /isbnsize 9 def
  1304.     /isbnpos (unset) def
  1305.     /height 1 def
  1306.     /addongap 12 def   
  1307.  
  1308.     % Parse the input options
  1309.     options type /stringtype eq {
  1310.         1 dict begin
  1311.         options {
  1312.             token false eq {exit} if dup length string cvs (=) search
  1313.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  1314.         } loop
  1315.         currentdict end /options exch def
  1316.     } if
  1317.     options {def} forall
  1318.     
  1319.     /isbnfont isbnfont cvlit def
  1320.     /isbnsize isbnsize cvr def
  1321.     /height height cvr def
  1322.     /addongap addongap cvr def
  1323.     isbnpos (unset) eq {
  1324.         /isbnpos height 72 mul 3 add def
  1325.     } {
  1326.         /isbnpos isbnpos cvr def
  1327.     } ifelse
  1328.    
  1329.     % Split off the addon
  1330.     isbntxt ( ) search {
  1331.         /isbntxt exch def
  1332.         pop
  1333.         /addon exch def
  1334.     } {
  1335.         pop
  1336.         /addon () def
  1337.     } ifelse
  1338.  
  1339.     % Read the digits from isbntxt and calculate checksums
  1340.     /isbn 13 string def
  1341.     /checksum10 0 def
  1342.     /checksum13 0 def
  1343.     /i 0 def /n 0 def
  1344.     { % loop
  1345.         /isbnchar isbntxt i get 48 sub def
  1346.         isbnchar -3 ne {     % Ignore dashes
  1347.             isbn n isbnchar 48 add put
  1348.             n 9 lt {
  1349.                 /checksum10 checksum10 10 n sub isbnchar mul add def
  1350.             } if
  1351.             n 12 lt {
  1352.                 n 2 mod 0 eq {
  1353.                     /checksum13 isbnchar checksum13 add def
  1354.                 } {
  1355.                     /checksum13 isbnchar 3 mul checksum13 add def
  1356.                 } ifelse
  1357.             } if
  1358.             /n n 1 add def
  1359.         } if
  1360.         /i i 1 add def
  1361.         i isbntxt length eq {exit} if
  1362.     } loop
  1363.  
  1364.     % Add the ISBN header to the isbntxt
  1365.     n 9 eq n 10 eq or {
  1366.         /checksum 11 checksum10 11 mod sub 11 mod def
  1367.         /isbn isbn 0 9 getinterval def
  1368.         /pad 18 string def
  1369.     } {
  1370.         /checksum 10 checksum13 10 mod sub 10 mod def
  1371.         /isbn isbn 0 12 getinterval def
  1372.         /pad 22 string def
  1373.     } ifelse
  1374.     pad 0 (ISBN ) putinterval
  1375.     pad 5 isbntxt putinterval  % Add isbntxt to the pad
  1376.  
  1377.     % Add checksum digit
  1378.     pad pad length 2 sub 45 put  % Put a dash
  1379.     checksum 10 eq {
  1380.         pad pad length 1 sub checksum 78 add put  % Check digit for 10 is X
  1381.     } {
  1382.         pad pad length 1 sub checksum 48 add put  % Put check digit
  1383.     } ifelse
  1384.     /isbntxt pad def
  1385.  
  1386.     % Convert ISBN digits to EAN-13
  1387.     /barcode 12 string def
  1388.     isbn length 9 eq {        
  1389.         barcode 0 (978) putinterval
  1390.         barcode 3 isbn putinterval
  1391.     } {
  1392.         barcode 0 isbn putinterval
  1393.     } ifelse
  1394.  
  1395.     % Append the addon
  1396.     addon () ne {
  1397.         12 addon length add 1 add string 
  1398.         dup 0 barcode putinterval
  1399.         dup 12 ( ) putinterval
  1400.         dup 13 addon putinterval
  1401.         /barcode exch def
  1402.     } if
  1403.  
  1404.     % Get the result of encoding with ean13
  1405.     options (dontdraw) true put
  1406.     options (addongap) addongap put 
  1407.     /args barcode options //ean13 exec def
  1408.  
  1409.     % Add the ISBN text
  1410.     includetext {
  1411.         isbn length 9 eq {
  1412.             /isbnxpos -1 def
  1413.         } {
  1414.             /isbnxpos -12 def
  1415.         } ifelse
  1416.         args (txt) known {
  1417.             /txt args (txt) get def
  1418.             /newtxt txt length 1 add array def
  1419.             newtxt 0 txt putinterval
  1420.             newtxt newtxt length 1 sub [isbntxt isbnxpos isbnpos isbnfont isbnsize] put
  1421.             args (txt) newtxt put
  1422.         } {
  1423.             args (txt) [ [isbntxt isbnxpos isbnpos isbnfont isbnsize] ] put
  1424.         } ifelse
  1425.     } if
  1426.  
  1427.     args (opt) options put
  1428.     args
  1429.  
  1430.     dontdraw not {//renlinear exec} if
  1431.  
  1432.     end
  1433.  
  1434. } bind def
  1435. % --END ENCODER isbn--
  1436.  
  1437. % --BEGIN ENCODER code128--
  1438. % --DESC: Code 128
  1439. % --EXAM: ^104^102Count^0990123456789^101!
  1440. % --EXOP: includetext
  1441. % --RNDR: renlinear
  1442. /code128 {
  1443.  
  1444.     1 dict begin                  % Confine variables to local scope
  1445.  
  1446.     /options exch def        % We are given an option string
  1447.     /barcode exch def        % We are given a barcode string
  1448.  
  1449.     /dontdraw false def
  1450.     /includetext false def    % Enable/disable text
  1451.     /textfont /Courier def
  1452.     /textsize 10 def
  1453.     /textyoffset -7 def
  1454.     /height 1 def
  1455.     
  1456.     % Parse the input options
  1457.     options type /stringtype eq {
  1458.         1 dict begin
  1459.         options {
  1460.             token false eq {exit} if dup length string cvs (=) search
  1461.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  1462.         } loop
  1463.         currentdict end /options exch def
  1464.     } if
  1465.     options {def} forall
  1466.  
  1467.     /textfont textfont cvlit def
  1468.     /textsize textsize cvr def
  1469.     /textyoffset textyoffset cvr def
  1470.     /height height cvr def
  1471.     
  1472.     % Create an array containing the character mappings
  1473.     /encs
  1474.     [ (212222) (222122) (222221) (121223) (121322) (131222) (122213)
  1475.       (122312) (132212) (221213) (221312) (231212) (112232) (122132)
  1476.       (122231) (113222) (123122) (123221) (223211) (221132) (221231)
  1477.       (213212) (223112) (312131) (311222) (321122) (321221) (312212)
  1478.       (322112) (322211) (212123) (212321) (232121) (111323) (131123)
  1479.       (131321) (112313) (132113) (132311) (211313) (231113) (231311)
  1480.       (112133) (112331) (132131) (113123) (113321) (133121) (313121)
  1481.       (211331) (231131) (213113) (213311) (213131) (311123) (311321)
  1482.       (331121) (312113) (312311) (332111) (314111) (221411) (431111)
  1483.       (111224) (111422) (121124) (121421) (141122) (141221) (112214)
  1484.       (112412) (122114) (122411) (142112) (142211) (241211) (221114)
  1485.       (413111) (241112) (134111) (111242) (121142) (121241) (114212)
  1486.       (124112) (124211) (411212) (421112) (421211) (212141) (214121)
  1487.       (412121) (111143) (111341) (131141) (114113) (114311) (411113)
  1488.       (411311) (113141) (114131) (311141) (411131) (211412) (211214)
  1489.       (211232) (2331112)
  1490.     ] def
  1491.  
  1492.     % Create a string of the available characters for alphabets A and B
  1493.     /barchars ( !"#$%&'\(\)*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~) def
  1494.     /barlen barcode length def    % Length of the code
  1495.     /sbs barlen 6 mul string def  % sbs is 6 times length of barcode
  1496.     /txt barlen array def
  1497.  
  1498.     /mode -1 def         % A=0, B=1, C=2
  1499.     /checksum barcode 1 3 getinterval cvi def  % Initialise the checksum
  1500.  
  1501.     /i 0 def /j 0 def
  1502.     { % loop
  1503.         i barlen eq {exit} if
  1504.         barcode i 1 getinterval (^) eq {
  1505.             % indx is given by the next three characters
  1506.             /indx barcode i 1 add 3 getinterval cvi def
  1507.             txt j [( ) j 11 mul textyoffset textfont textsize] put
  1508.             /i i 4 add def
  1509.         } {
  1510.             % indx depends on the mode
  1511.             mode 2 eq {
  1512.                 /indx barcode i 2 getinterval cvi def
  1513.                 txt j [barcode i 2 getinterval j 11 mul textyoffset textfont textsize] put
  1514.                 /i i 2 add def
  1515.             } {
  1516.                 barchars barcode i 1 getinterval search
  1517.                 pop                    % Discard true leaving pre
  1518.                 length /indx exch def  % indx is the length of pre
  1519.                 pop pop                % Discard seek and post
  1520.                 txt j [barchars indx 1 getinterval j 11 mul textyoffset textfont textsize] put
  1521.                 /i i 1 add def
  1522.             } ifelse
  1523.         } ifelse
  1524.         /enc encs indx get def         % Get the indxth encoding
  1525.         sbs j 6 mul enc putinterval    % Put encoded digit into sbs
  1526.  
  1527.         % Update the mode
  1528.         indx 101 eq indx 103 eq or {/mode 0 def} if
  1529.         indx 100 eq indx 104 eq or {/mode 1 def} if
  1530.         indx 99 eq indx 105 eq or {/mode 2 def} if
  1531.  
  1532.         /checksum indx j mul checksum add def  % checksum+=indx*j
  1533.         /j j 1 add def
  1534.     } loop
  1535.  
  1536.     % Put the checksum character
  1537.     /checksum checksum 103 mod def
  1538.     sbs j 6 mul encs checksum get putinterval
  1539.  
  1540.     % Put the end character
  1541.     sbs j 6 mul 6 add encs 106 get putinterval
  1542.  
  1543.     % Shrink sbs and txt to fit exactly
  1544.     /sbs sbs 0 j 6 mul 13 add getinterval def
  1545.     /txt txt 0 j getinterval def
  1546.  
  1547.     % Return the arguments
  1548.     <<
  1549.     /ren (renlinear)
  1550.     /sbs [sbs {48 sub} forall]
  1551.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  1552.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  1553.     includetext {
  1554.         /txt txt
  1555.     } if
  1556.     /opt options
  1557.     >>
  1558.  
  1559.     dontdraw not {//renlinear exec} if
  1560.  
  1561.     end
  1562.  
  1563. } bind def
  1564. % --END ENCODER code128--
  1565.  
  1566. % --BEGIN ENCODER code39--
  1567. % --DESC: Code 39
  1568. % --EXAM: THIS IS CODE 39
  1569. % --EXOP: includetext includecheck includecheckintext
  1570. % --RNDR: renlinear
  1571. /code39 {
  1572.  
  1573.     1 dict begin                 % Confine variables to local scope
  1574.  
  1575.     /options exch def       % We are given an option string
  1576.     /barcode exch def       % We are given a barcode string
  1577.  
  1578.     /dontdraw false def
  1579.     /includecheck false def  % Enable/disable checkdigit
  1580.     /includetext false def
  1581.     /includecheckintext false def
  1582.     /hidestars false def
  1583.     /textfont /Courier def
  1584.     /textsize 10 def
  1585.     /textyoffset -7 def
  1586.     /height 1 def
  1587.     
  1588.     % Parse the input options
  1589.     options type /stringtype eq {
  1590.         1 dict begin
  1591.         options {
  1592.             token false eq {exit} if dup length string cvs (=) search
  1593.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  1594.         } loop
  1595.         currentdict end /options exch def
  1596.     } if
  1597.     options {def} forall
  1598.  
  1599.     /textfont textfont cvlit def
  1600.     /textsize textsize cvr def
  1601.     /textyoffset textyoffset cvr def
  1602.     /height height cvr def
  1603.     
  1604.     % Create an array containing the character mappings
  1605.     /encs
  1606.     [ (1113313111) (3113111131) (1133111131) (3133111111) (1113311131)
  1607.       (3113311111) (1133311111) (1113113131) (3113113111) (1133113111)
  1608.       (3111131131) (1131131131) (3131131111) (1111331131) (3111331111)
  1609.       (1131331111) (1111133131) (3111133111) (1131133111) (1111333111)
  1610.       (3111111331) (1131111331) (3131111311) (1111311331) (3111311311)
  1611.       (1131311311) (1111113331) (3111113311) (1131113311) (1111313311)
  1612.       (3311111131) (1331111131) (3331111111) (1311311131) (3311311111)
  1613.       (1331311111) (1311113131) (3311113111) (1331113111) (1313131111)
  1614.       (1313111311) (1311131311) (1113131311) (1311313111)
  1615.     ] def
  1616.  
  1617.     % Create a string of the available characters
  1618.     /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*) def
  1619.  
  1620.     /barlen barcode length def  % Length of the code
  1621.  
  1622.     includecheck {
  1623.         /sbs barlen 10 mul 30 add string def
  1624.         /txt barlen 3 add array def
  1625.     } {
  1626.         /sbs barlen 10 mul 20 add string def
  1627.         /txt barlen 2 add array def
  1628.     } ifelse
  1629.  
  1630.     /checksum 0 def
  1631.  
  1632.     % Put the start character
  1633.     sbs 0 encs 43 get putinterval
  1634.     hidestars not {
  1635.         txt 0 [(*) 0 textyoffset textfont textsize] put
  1636.     } {
  1637.         txt 0 [() 0 textyoffset textfont textsize] put
  1638.     } ifelse
  1639.  
  1640.     0 1 barlen 1 sub {
  1641.         /i exch def
  1642.         % Lookup the encoding for the each barcode character
  1643.         barcode i 1 getinterval barchars exch search
  1644.         pop                                  % Discard true leaving pre
  1645.         length /indx exch def                % indx is the length of pre
  1646.         pop pop                              % Discard seek and post
  1647.         /enc encs indx get def               % Get the indxth encoding
  1648.         sbs i 10 mul 10 add enc putinterval  % Put encoded digit into sbs
  1649.         txt i 1 add [barcode i 1 getinterval i 1 add 16 mul textyoffset textfont textsize] put
  1650.         /checksum checksum indx add def
  1651.     } for
  1652.  
  1653.     % Put the checksum and end characters
  1654.     includecheck {
  1655.         /checksum checksum 43 mod def
  1656.         sbs barlen 10 mul 10 add encs checksum get putinterval
  1657.         includecheckintext {
  1658.             txt barlen 1 add [barchars checksum 1 getinterval barlen 1 add 16 mul textyoffset textfont textsize] put
  1659.         } {
  1660.             txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put
  1661.         } ifelse
  1662.         sbs barlen 10 mul 20 add encs 43 get putinterval
  1663.         hidestars not {
  1664.             txt barlen 2 add [(*) barlen 2 add 16 mul textyoffset textfont textsize] put
  1665.         } {
  1666.             txt barlen 2 add [() barlen 2 add 16 mul textyoffset textfont textsize] put
  1667.         } ifelse
  1668.     } {
  1669.         sbs barlen 10 mul 10 add encs 43 get putinterval
  1670.         hidestars not {
  1671.             txt barlen 1 add [(*) barlen 1 add 16 mul textyoffset textfont textsize] put
  1672.         } {
  1673.             txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put
  1674.         } ifelse
  1675.     } ifelse
  1676.     
  1677.     % Return the arguments
  1678.     <<
  1679.     /ren (renlinear)
  1680.     /sbs [sbs {48 sub} forall]
  1681.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  1682.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  1683.     includetext {
  1684.         /txt txt
  1685.     } if
  1686.     /opt options
  1687.     >>
  1688.  
  1689.     dontdraw not {//renlinear exec} if
  1690.  
  1691.     end
  1692.  
  1693. } bind def
  1694. % --END ENCODER code39--
  1695.  
  1696. % --BEGIN ENCODER code93--
  1697. % --DESC: Code 93
  1698. % --EXAM: THIS IS CODE 93
  1699. % --EXOP: includetext includecheck
  1700. % --RNDR: renlinear
  1701. /code93 {
  1702.  
  1703.     1 dict begin                 % Confine variables to local scope
  1704.  
  1705.     /options exch def       % We are given an option string
  1706.     /barcode exch def       % We are given a barcode string
  1707.  
  1708.     /dontdraw false def
  1709.     /includecheck false def  % Enable/disable checkdigit
  1710.     /includetext false def   % Enable/disable text
  1711.     /textfont /Courier def
  1712.     /textsize 10 def
  1713.     /textyoffset -7 def
  1714.     /height 1 def
  1715.     
  1716.     % Parse the input options
  1717.     options type /stringtype eq {
  1718.         1 dict begin
  1719.         options {
  1720.             token false eq {exit} if dup length string cvs (=) search
  1721.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  1722.         } loop
  1723.         currentdict end /options exch def
  1724.     } if
  1725.     options {def} forall
  1726.  
  1727.     /textfont textfont cvlit def
  1728.     /textsize textsize cvr def
  1729.     /textyoffset textyoffset cvr def
  1730.     /height height cvr def
  1731.     
  1732.     /encs
  1733.     [ (131112) (111213) (111312) (111411) (121113)
  1734.       (121212) (121311) (111114) (131211) (141111)
  1735.       (211113) (211212) (211311) (221112) (221211)
  1736.       (231111) (112113) (112212) (112311) (122112)
  1737.       (132111) (111123) (111222) (111321) (121122)
  1738.       (131121) (212112) (212211) (211122) (211221)
  1739.       (221121) (222111) (112122) (112221) (122121)
  1740.       (123111) (121131) (311112) (311211) (321111)
  1741.       (112131) (113121) (211131) (121221) (312111)
  1742.       (311121) (122211) (111141) (1111411)
  1743.     ] def
  1744.  
  1745.     % Create a string of the available characters
  1746.     /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
  1747.  
  1748.     /barlen barcode length def  % Length of the code    
  1749.     barcode {
  1750.         (^) search false eq {pop exit} if
  1751.         pop pop /barlen barlen 3 sub def
  1752.     } loop
  1753.  
  1754.     includecheck {
  1755.         /sbs barlen 6 mul 25 add string def
  1756.     } {
  1757.         /sbs barlen 6 mul 13 add string def
  1758.     } ifelse
  1759.     /txt barlen array def
  1760.     
  1761.     % Put the start character
  1762.     sbs 0 encs 47 get putinterval
  1763.     
  1764.     /checksum1 0 def /checksum2 0 def
  1765.  
  1766.     /i 0 def /j 0 def
  1767.     { % loop
  1768.         j barlen eq {exit} if
  1769.         barcode i 1 getinterval (^) eq {
  1770.             % indx is given by the next three characters
  1771.             /indx barcode i 1 add 3 getinterval cvi def
  1772.             txt j [( ) j 9 mul 9 add textyoffset textfont textsize] put
  1773.             /i i 4 add def
  1774.         } {
  1775.             barchars barcode i 1 getinterval search
  1776.             pop                         % Discard true leaving pre
  1777.             length /indx exch def       % indx is the length of pre
  1778.             pop pop                     % Discard seek and post
  1779.             txt j [barchars indx 1 getinterval j 9 mul 9 add textyoffset textfont textsize] put
  1780.             /i i 1 add def
  1781.         } ifelse
  1782.         /enc encs indx get def             % Get the indxth encoding
  1783.         sbs j 6 mul 6 add enc putinterval  % Put encoded digit into sbs
  1784.         /checksum1 checksum1 barlen j sub 1 sub 20 mod 1 add indx mul add def
  1785.         /checksum2 checksum2 barlen j sub 15 mod 1 add indx mul add def
  1786.         /j j 1 add def
  1787.     } loop
  1788.     
  1789.     includecheck {
  1790.         % Put the first checksum character
  1791.         /checksum1 checksum1 47 mod def
  1792.         /checksum2 checksum2 checksum1 add 47 mod def
  1793.         sbs j 6 mul 6 add encs checksum1 get putinterval
  1794.         sbs j 6 mul 12 add encs checksum2 get putinterval
  1795.         % Put the end character
  1796.         sbs j 6 mul 18 add encs 48 get putinterval
  1797.     } {
  1798.         % Put the end character
  1799.         sbs j 6 mul 6 add encs 48 get putinterval      
  1800.     } ifelse
  1801.  
  1802.     % Return the arguments
  1803.     <<
  1804.     /ren (renlinear)
  1805.     /sbs [sbs {48 sub} forall]
  1806.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  1807.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  1808.     includetext {
  1809.         /txt txt
  1810.     } if
  1811.     /opt options
  1812.     >>
  1813.  
  1814.     dontdraw not {//renlinear exec} if
  1815.  
  1816.     end
  1817.  
  1818. } bind def
  1819. % --END ENCODER code93--
  1820.  
  1821. % --BEGIN ENCODER interleaved2of5--
  1822. % --DESC: Interleaved 2 of 5 (ITF)
  1823. % --EXAM: 24012345678905
  1824. % --EXOP: showborder borderwidth=4 borderleft=15 borderright=15 height=0.5 includecheck includetext includecheckintext textyoffset=-10
  1825. % --RNDR: renlinear
  1826. /interleaved2of5 {
  1827.  
  1828.     1 dict begin         % Confine variables to local scope
  1829.  
  1830.     /options exch def               % We are given an option string
  1831.     /barcode exch def               % We are given a barcode string
  1832.  
  1833.     /dontdraw false def
  1834.     /includecheck false def         % Enable/disable checkdigit
  1835.     /includetext false def          % Enable/disable text
  1836.     /includecheckintext false def
  1837.     /textfont /Courier def
  1838.     /textsize 10 def
  1839.     /textyoffset -7 def
  1840.     /height 1 def
  1841.     
  1842.     % Parse the input options
  1843.     options type /stringtype eq {
  1844.         1 dict begin
  1845.         options {
  1846.             token false eq {exit} if dup length string cvs (=) search
  1847.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  1848.         } loop
  1849.         currentdict end /options exch def
  1850.     } if
  1851.     options {def} forall
  1852.     
  1853.     /textfont textfont cvlit def
  1854.     /textsize textsize cvr def
  1855.     /textyoffset textyoffset cvr def
  1856.     /height height cvr def
  1857.     
  1858.     /barlen barcode length def      % Length of the code
  1859.  
  1860.     % Prefix 0 to barcode if length is even and including checkdigit
  1861.     % or length is odd and not including checkdigit
  1862.     barlen 2 mod 0 eq includecheck and          % even & includecheck
  1863.     barlen 2 mod 0 ne includecheck not and or { % odd  & !includecheck
  1864.         /pad barlen 1 add string def  % Create pad one bigger than barcode
  1865.         pad 0 48 put                  % Put ascii 0 at start of pad
  1866.         pad 1 barcode putinterval     % Add barcode to the end of pad
  1867.         /barcode pad def              % barcode=pad
  1868.         /barlen barlen 1 add def      % barlen++
  1869.     } if
  1870.  
  1871.     % Add checksum to end of barcode
  1872.     includecheck {
  1873.         /checksum 0 def
  1874.         0 1 barlen 1 sub {
  1875.             /i exch def
  1876.             i 2 mod 0 eq {
  1877.                 /checksum checksum barcode i get 48 sub 3 mul add def
  1878.             } {
  1879.                 /checksum checksum barcode i get 48 sub add def
  1880.             } ifelse
  1881.         } for
  1882.         /checksum 10 checksum 10 mod sub 10 mod def
  1883.         /pad barlen 1 add string def    % Create pad one bigger than barcode
  1884.         pad 0 barcode putinterval       % Add barcode to the start of pad
  1885.         pad barlen checksum 48 add put  % Add checksum to end of pad
  1886.         /barcode pad def                % barcode=pad
  1887.         /barlen barlen 1 add def        % barlen++
  1888.     } if
  1889.  
  1890.     % Create an array containing the character mappings
  1891.     /encs
  1892.     [ (11331) (31113) (13113) (33111) (11313)
  1893.       (31311) (13311) (11133) (31131) (13131)
  1894.       (1111)  (3111)
  1895.     ] def
  1896.  
  1897.     % Create a string of the available characters
  1898.     /barchars (0123456789) def
  1899.     /sbs barlen 5 mul 8 add string def
  1900.     /txt barlen array def
  1901.  
  1902.     % Put the start character
  1903.     sbs 0 encs 10 get putinterval
  1904.  
  1905.     0 2 barlen 1 sub {
  1906.     /i exch def
  1907.         % Lookup the encodings for two consecutive barcode characters
  1908.         barcode i 1 getinterval barchars exch search
  1909.         pop                           % Discard true leaving pre
  1910.         length /indx exch def         % indx is the length of pre
  1911.         pop pop                       % Discard seek and post
  1912.         /enca encs indx get def       % Get the indxth encoding
  1913.  
  1914.         barcode i 1 add 1 getinterval barchars exch search
  1915.         pop                           % Discard true leaving pre
  1916.         length /indx exch def         % indx is the length of pre
  1917.         pop pop                       % Discard seek and post
  1918.         /encb encs indx get def       % Get the indxth encoding
  1919.  
  1920.         % Interleave the two character encodings
  1921.         /intl enca length 2 mul string def
  1922.         0 1 enca length 1 sub {
  1923.             /j exch def
  1924.             /achar enca j get def
  1925.             /bchar encb j get def
  1926.             intl j 2 mul achar put
  1927.             intl j 2 mul 1 add bchar put
  1928.         } for
  1929.  
  1930.         sbs i 5 mul 4 add intl putinterval   % Put encoded digit into sbs
  1931.         txt i [barcode i 1 getinterval i 9 mul 4 add textyoffset textfont textsize] put
  1932.         includecheck includecheckintext not and barlen 2 sub i eq and {
  1933.             txt i 1 add [( ) i 1 add 9 mul 4 add textyoffset textfont textsize] put
  1934.         } {
  1935.             txt i 1 add [barcode i 1 add 1 getinterval i 1 add 9 mul 4 add textyoffset textfont textsize] put
  1936.         } ifelse
  1937.     } for
  1938.  
  1939.     % Put the end character
  1940.     sbs barlen 5 mul 4 add encs 11 get putinterval
  1941.  
  1942.     % Return the arguments
  1943.     <<
  1944.     /ren (renlinear)
  1945.     /sbs [sbs {48 sub} forall]
  1946.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  1947.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  1948.     includetext {
  1949.         /txt txt
  1950.     } if
  1951.     /opt options
  1952.     >>
  1953.  
  1954.     dontdraw not {//renlinear exec} if
  1955.  
  1956.     end
  1957.  
  1958. } bind def
  1959. % --END ENCODER interleaved2of5--
  1960.  
  1961. % --BEGIN ENCODER rss14--
  1962. % --DESC: Reduced Space Symbology 14 (RSS-14)
  1963. % --EXAM: 24012345678905
  1964. % --EXOP: height=0.3
  1965. % --RNDR: renlinear
  1966. /rss14 {
  1967.  
  1968.     1 dict begin            % Confine variables to local scope
  1969.  
  1970.     /options exch def  % We are given an option string
  1971.     /barcode exch def  % We are given a barcode string
  1972.  
  1973.     /dontdraw false def
  1974.     /height 1 def
  1975.     /linkage false def
  1976.     
  1977.     % Parse the input options
  1978.     options type /stringtype eq {
  1979.         1 dict begin
  1980.         options {
  1981.             token false eq {exit} if dup length string cvs (=) search
  1982.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  1983.         } loop
  1984.         currentdict end /options exch def
  1985.     } if
  1986.     options {def} forall
  1987.    
  1988.     % Create the human readable text
  1989.     /txt barcode length array def
  1990.     0 1 barcode length 1 sub {
  1991.         /i exch def
  1992.         txt i [barcode i 1 getinterval 0 0 () 0] put
  1993.     } for
  1994.  
  1995.     /height height cvr def
  1996.  
  1997.     /ncr {  % n r
  1998.         2 copy sub 2 copy lt {exch} if  % n r maxd mind
  1999.         1 1 5 3 roll  % mind j=1 v=1 n maxd
  2000.         1 add -1 exch {  % mind j v  n -1 maxd+1
  2001.             mul  % mind j v*i
  2002.             1 index 3 index le {
  2003.                 1 index idiv exch 1 add exch
  2004.             } if
  2005.         } for
  2006.         {  % mind j v
  2007.             1 index 3 index gt {exit} if
  2008.             1 index idiv exch 1 add exch
  2009.         } loop
  2010.         exch pop exch pop
  2011.     } bind def
  2012.      
  2013.     /getRSSwidths {
  2014.         /oe exch def
  2015.         /el exch def
  2016.         /mw exch def
  2017.         /nm exch def
  2018.         /val exch def
  2019.         /out el array def
  2020.         /mask 0 def
  2021.         0 1 el 2 sub {
  2022.             /bar exch def
  2023.             /ew 1 def 
  2024.             /mask mask 1 bar bitshift or def {
  2025.                 /sval nm ew sub 1 sub el bar sub 2 sub ncr def
  2026.                 oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and {
  2027.                     /sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def
  2028.                 } if
  2029.                 el bar sub 2 gt {
  2030.                     /lval 0 def
  2031.                     nm ew sub el sub bar add 2 add -1 mw 1 add {
  2032.                         nm exch sub ew sub 1 sub el bar sub 3 sub ncr
  2033.                         /lval exch lval add def
  2034.                     } for
  2035.                     /sval sval lval el bar sub 1 sub mul sub def
  2036.                 } {
  2037.                     nm ew sub mw gt {/sval sval 1 sub def} if
  2038.                 } ifelse
  2039.                 /val val sval sub def
  2040.                 val 0 lt {exit} if
  2041.                 /ew ew 1 add def
  2042.                 /mask mask 1 bar bitshift not and def
  2043.             } loop  
  2044.             /val val sval add def
  2045.             /nm nm ew sub def
  2046.             out bar ew put 
  2047.         } for
  2048.         out el 1 sub nm put
  2049.         out
  2050.     } bind def
  2051.  
  2052.     /binval [barcode {48 sub} forall] def
  2053.     /binval [linkage {1} {0} ifelse binval 0 13 getinterval {} forall] def
  2054.     
  2055.     0 1 12 {
  2056.         /i exch def
  2057.         binval i 1 add 2 copy get binval i get 4537077 mod 10 mul add put
  2058.         binval i binval i get 4537077 idiv put
  2059.     } for
  2060.     /right binval 13 get 4537077 mod def
  2061.     binval 13 2 copy get 4537077 idiv put
  2062.  
  2063.     /left 0 def
  2064.     /i true def
  2065.     0 1 13 {
  2066.         /j exch def
  2067.         binval j get
  2068.         dup 0 eq i and {
  2069.             pop
  2070.         } {
  2071.             /i false def
  2072.             /left left 3 -1 roll 10 13 j sub exp cvi mul add def
  2073.         } ifelse
  2074.     } for
  2075.     
  2076.     /d1 left 1597 idiv def
  2077.     /d2 left 1597 mod def
  2078.     /d3 right 1597 idiv def
  2079.     /d4 right 1597 mod def
  2080.  
  2081.     /tab164 [
  2082.         160   0     12 4   8 1  161   1
  2083.         960   161   10 6   6 3  80   10
  2084.         2014  961   8  8   4 5  31   34
  2085.         2714  2015  6  10  3 6  10   70
  2086.         2840  2715  4  12  1 8  1    126
  2087.     ] def
  2088.  
  2089.     /tab154 [
  2090.         335   0     5  10  2 7  4   84
  2091.         1035  336   7  8   4 5  20  35
  2092.         1515  1036  9  6   6 3  48  10
  2093.         1596  1516  11 4   8 1  81  1
  2094.     ] def
  2095.  
  2096.     /i 0 def {
  2097.         d1 tab164 i get le {
  2098.             tab164 i 1 add 7 getinterval {} forall
  2099.             /d1te exch def /d1to exch def
  2100.             /d1mwe exch def /d1mwo exch def
  2101.             /d1ele exch def /d1elo exch def
  2102.             /d1gs exch def
  2103.             exit
  2104.         } if
  2105.         /i i 8 add def
  2106.     } loop
  2107.  
  2108.     /i 0 def {
  2109.         d2 tab154 i get le {
  2110.             tab154 i 1 add 7 getinterval {} forall
  2111.             /d2te exch def /d2to exch def
  2112.             /d2mwe exch def /d2mwo exch def
  2113.             /d2ele exch def /d2elo exch def
  2114.             /d2gs exch def
  2115.             exit
  2116.         } if
  2117.         /i i 8 add def
  2118.     } loop
  2119.  
  2120.     /i 0 def {
  2121.         d3 tab164 i get le {
  2122.             tab164 i 1 add 7 getinterval {} forall
  2123.             /d3te exch def /d3to exch def
  2124.             /d3mwe exch def /d3mwo exch def
  2125.             /d3ele exch def /d3elo exch def
  2126.             /d3gs exch def
  2127.             exit
  2128.         } if
  2129.         /i i 8 add def
  2130.     } loop
  2131.  
  2132.     /i 0 def {
  2133.         d4 tab154 i get le {
  2134.             tab154 i 1 add 7 getinterval {} forall
  2135.             /d4te exch def /d4to exch def
  2136.             /d4mwe exch def /d4mwo exch def
  2137.             /d4ele exch def /d4elo exch def
  2138.             /d4gs exch def
  2139.             exit
  2140.         } if
  2141.         /i i 8 add def
  2142.     } loop
  2143.     
  2144.     /d1wo d1 d1gs sub d1te idiv d1elo d1mwo 4 false getRSSwidths def
  2145.     /d1we d1 d1gs sub d1te mod  d1ele d1mwe 4 true  getRSSwidths def
  2146.     /d2wo d2 d2gs sub d2to mod  d2elo d2mwo 4 true  getRSSwidths def
  2147.     /d2we d2 d2gs sub d2to idiv d2ele d2mwe 4 false getRSSwidths def
  2148.     /d3wo d3 d3gs sub d3te idiv d3elo d3mwo 4 false getRSSwidths def
  2149.     /d3we d3 d3gs sub d3te mod  d3ele d3mwe 4 true  getRSSwidths def
  2150.     /d4wo d4 d4gs sub d4to mod  d4elo d4mwo 4 true  getRSSwidths def
  2151.     /d4we d4 d4gs sub d4to idiv d4ele d4mwe 4 false getRSSwidths def
  2152.  
  2153.     /d1w 8 array def
  2154.     0 1 3 {
  2155.         /i exch def
  2156.         d1w i 2 mul d1wo i get put
  2157.         d1w i 2 mul 1 add d1we i get put
  2158.     } for
  2159.  
  2160.     /d2w 8 array def
  2161.     0 1 3 {
  2162.         /i exch def
  2163.         d2w 7 i 2 mul sub d2wo i get put
  2164.         d2w 6 i 2 mul sub d2we i get put
  2165.     } for
  2166.     
  2167.     /d3w 8 array def
  2168.     0 1 3 {
  2169.         /i exch def
  2170.         d3w 7 i 2 mul sub d3wo i get put
  2171.         d3w 6 i 2 mul sub d3we i get put
  2172.     } for
  2173.     
  2174.     /d4w 8 array def
  2175.     0 1 3 {
  2176.         /i exch def
  2177.         d4w i 2 mul d4wo i get put
  2178.         d4w i 2 mul 1 add d4we i get put
  2179.     } for
  2180.  
  2181.     /widths [
  2182.         d1w {} forall
  2183.         d2w {} forall
  2184.         d3w {} forall
  2185.         d4w {} forall
  2186.     ] def
  2187.     
  2188.     /checkweights [
  2189.         1   3   9   27  2   6   18  54
  2190.         58  72  24  8   29  36  12  4
  2191.         74  51  17  32  37  65  48  16
  2192.         64  34  23  69  49  68  46  59
  2193.     ] def
  2194.  
  2195.     /checkwidths [
  2196.         3 8 2 1 1   3 5 5 1 1   3 3 7 1 1
  2197.         3 1 9 1 1   2 7 4 1 1   2 5 6 1 1
  2198.         2 3 8 1 1   1 5 7 1 1   1 3 9 1 1
  2199.     ] def
  2200.     
  2201.     /checksum 0 def
  2202.     0 1 31 {
  2203.         /i exch def
  2204.         /checksum checksum widths i get checkweights i get mul add def 
  2205.     } for
  2206.     /checksum checksum 79 mod def    
  2207.     checksum 8 ge {/checksum checksum 1 add def} if
  2208.     checksum 72 ge {/checksum checksum 1 add def} if
  2209.     /checklt checkwidths checksum 9 idiv 5 mul 5 getinterval def
  2210.     /checkrtrev checkwidths checksum 9 mod 5 mul 5 getinterval def
  2211.     /checkrt 5 array def
  2212.     0 1 4 {
  2213.         /i exch def
  2214.         checkrt i checkrtrev 4 i sub get put
  2215.     } for
  2216.  
  2217.     /sbs [
  2218.         1 d1w {} forall checklt {} forall d2w {}
  2219.         forall d4w {} forall checkrt {} forall d3w {} forall 1 1
  2220.     ] def
  2221.     
  2222.     % Return the arguments
  2223.     <<
  2224.     /ren (renlinear)
  2225.     /sbs sbs
  2226.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  2227.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  2228.     /txt txt
  2229.     /textxalign (center)
  2230.     /opt options
  2231.     >>
  2232.  
  2233.     dontdraw not {//renlinear exec} if
  2234.  
  2235.     end
  2236.  
  2237. } bind def
  2238. % --END ENCODER rss14--
  2239.  
  2240. % --BEGIN ENCODER rsslimited--
  2241. % --DESC: Reduced Space Symbology Limited (RSS-Limited)
  2242. % --EXAM: 00978186074271
  2243. % --EXOP: height=0.3
  2244. % --RNDR: renlinear
  2245. /rsslimited {
  2246.  
  2247.     1 dict begin            % Confine variables to local scope
  2248.  
  2249.     /options exch def  % We are given an option string
  2250.     /barcode exch def  % We are given a barcode string
  2251.  
  2252.     /dontdraw false def
  2253.     /height 1 def
  2254.     
  2255.     % Parse the input options
  2256.     options type /stringtype eq {
  2257.         1 dict begin
  2258.         options {
  2259.             token false eq {exit} if dup length string cvs (=) search
  2260.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  2261.         } loop
  2262.         currentdict end /options exch def
  2263.     } if
  2264.     options {def} forall
  2265.    
  2266.     % Create the human readable text
  2267.     /txt barcode length array def
  2268.     0 1 barcode length 1 sub {
  2269.         /i exch def
  2270.         txt i [barcode i 1 getinterval 0 0 () 0] put
  2271.     } for
  2272.  
  2273.     /height height cvr def
  2274.  
  2275.     /ncr {  % n r
  2276.         2 copy sub 2 copy lt {exch} if  % n r maxd mind
  2277.         1 1 5 3 roll  % mind j=1 v=1 n maxd
  2278.         1 add -1 exch {  % mind j v  n -1 maxd+1
  2279.             mul  % mind j v*i
  2280.             1 index 3 index le {
  2281.                 1 index idiv exch 1 add exch
  2282.             } if
  2283.         } for
  2284.         {  % mind j v
  2285.             1 index 3 index gt {exit} if
  2286.             1 index idiv exch 1 add exch
  2287.         } loop
  2288.         exch pop exch pop
  2289.     } bind def
  2290.     
  2291.     /getRSSwidths {
  2292.         /oe exch def
  2293.         /el exch def
  2294.         /mw exch def
  2295.         /nm exch def
  2296.         /val exch def
  2297.         /out el array def
  2298.         /mask 0 def
  2299.         0 1 el 2 sub {
  2300.             /bar exch def
  2301.             /ew 1 def 
  2302.             /mask mask 1 bar bitshift or def {
  2303.                 /sval nm ew sub 1 sub el bar sub 2 sub ncr def
  2304.                 oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and {
  2305.                     /sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def
  2306.                 } if
  2307.                 el bar sub 2 gt {
  2308.                     /lval 0 def
  2309.                     nm ew sub el sub bar add 2 add -1 mw 1 add {
  2310.                         nm exch sub ew sub 1 sub el bar sub 3 sub ncr
  2311.                         /lval exch lval add def
  2312.                     } for
  2313.                     /sval sval lval el bar sub 1 sub mul sub def
  2314.                 } {
  2315.                     nm ew sub mw gt {/sval sval 1 sub def} if
  2316.                 } ifelse
  2317.                 /val val sval sub def
  2318.                 val 0 lt {exit} if
  2319.                 /ew ew 1 add def
  2320.                 /mask mask 1 bar bitshift not and def
  2321.             } loop  
  2322.             /val val sval add def
  2323.             /nm nm ew sub def
  2324.             out bar ew put 
  2325.         } for
  2326.         out el 1 sub nm put
  2327.         out
  2328.     } bind def
  2329.     
  2330.     /binval [barcode {48 sub} forall] def
  2331.     /binval [binval 0 13 getinterval {} forall] def
  2332.     
  2333.     0 1 11 {
  2334.         /i exch def
  2335.         binval i 1 add 2 copy get binval i get 2013571 mod 10 mul add put
  2336.         binval i binval i get 2013571 idiv put
  2337.     } for
  2338.     /d2 binval 12 get 2013571 mod def
  2339.     binval 12 2 copy get 2013571 idiv put
  2340.  
  2341.     /d1 0 def
  2342.     /i true def
  2343.     0 1 12 {
  2344.         /j exch def
  2345.         binval j get
  2346.         dup 0 eq i and {
  2347.             pop
  2348.         } {
  2349.             /i false def
  2350.             /d1 d1 3 -1 roll 10 12 j sub exp cvi mul add def
  2351.         } ifelse
  2352.     } for
  2353.     
  2354.     /tab267 [
  2355.         183063   0        17 9   6 3  6538   28
  2356.         820063   183064   13 13  5 4  875    728
  2357.         1000775  820064   9  17  3 6  28     6454
  2358.         1491020  1000776  15 11  5 4  2415   203
  2359.         1979844  1491021  11 15  4 5  203    2408
  2360.         1996938  1979845  19 7   8 1  17094  1
  2361.         2013570  1996939  7  19  1 8  1      16632
  2362.     ] def
  2363.  
  2364.     /i 0 def {
  2365.         d1 tab267 i get le {
  2366.             tab267 i 1 add 7 getinterval {} forall
  2367.             /d1te exch def /d1to exch def
  2368.             /d1mwe exch def /d1mwo exch def
  2369.             /d1ele exch def /d1elo exch def
  2370.             /d1gs exch def
  2371.             exit
  2372.         } if
  2373.         /i i 8 add def
  2374.     } loop
  2375.  
  2376.     /i 0 def {
  2377.         d2 tab267 i get le {
  2378.             tab267 i 1 add 7 getinterval {} forall
  2379.             /d2te exch def /d2to exch def
  2380.             /d2mwe exch def /d2mwo exch def
  2381.             /d2ele exch def /d2elo exch def
  2382.             /d2gs exch def
  2383.             exit
  2384.         } if
  2385.         /i i 8 add def
  2386.     } loop
  2387.  
  2388.     /d1wo d1 d1gs sub d1te idiv d1elo d1mwo 7 false getRSSwidths def    
  2389.     /d1we d1 d1gs sub d1te mod  d1ele d1mwe 7 true  getRSSwidths def
  2390.     /d2wo d2 d2gs sub d2te idiv d2elo d2mwo 7 false getRSSwidths def    
  2391.     /d2we d2 d2gs sub d2te mod  d2ele d2mwe 7 true  getRSSwidths def
  2392.  
  2393.     /d1w 14 array def
  2394.     0 1 6 {
  2395.         /i exch def
  2396.         d1w i 2 mul d1wo i get put
  2397.         d1w i 2 mul 1 add d1we i get put
  2398.     } for
  2399.  
  2400.     /d2w 14 array def
  2401.     0 1 6 {
  2402.         /i exch def
  2403.         d2w i 2 mul d2wo i get put
  2404.         d2w i 2 mul 1 add d2we i get put
  2405.     } for
  2406.  
  2407.     /widths [
  2408.         d1w {} forall
  2409.         d2w {} forall
  2410.     ] def
  2411.     
  2412.     /checkweights [
  2413.         1  3  9  27 81 65 17 51 64 14 42 37 22 66
  2414.         20 60 2  6  18 54 73 41 34 13 39 28 84 74
  2415.     ] def
  2416.  
  2417.     /checkseq [
  2418.         0 1 43 {} for
  2419.         45 52 57
  2420.         63 1 66 {} for
  2421.         73 1 79 {} for
  2422.         82
  2423.         126 1 130 {} for
  2424.         132
  2425.         141 1 146 {} for
  2426.         210 1 217 {} for
  2427.         220
  2428.         316 1 320 {} for
  2429.         322 323
  2430.         326 337
  2431.     ] def
  2432.    
  2433.     /checksum 0 def
  2434.     0 1 27 {
  2435.         /i exch def
  2436.         /checksum checksum widths i get checkweights i get mul add def
  2437.     } for
  2438.     /checksum checksum 89 mod def
  2439.     /seq checkseq checksum get def
  2440.     /swidths seq 21 idiv 8 3 6 false getRSSwidths def
  2441.     /bwidths seq 21 mod  8 3 6 false getRSSwidths def
  2442.  
  2443.     /checkwidths [0 0 0 0 0 0 0 0 0 0 0 0 1 1] def
  2444.     0 1 5 {
  2445.         /i exch def
  2446.         checkwidths i 2 mul swidths i get put
  2447.         checkwidths i 2 mul 1 add bwidths i get put
  2448.     } for
  2449.     
  2450.     /sbs [
  2451.         1 d1w {} forall checkwidths {} forall d2w {} forall 1 1
  2452.     ] def
  2453.     
  2454.     % Return the arguments
  2455.     <<
  2456.     /ren (renlinear)
  2457.     /sbs sbs
  2458.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  2459.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  2460.     /txt txt
  2461.     /textxalign (center)
  2462.     /opt options
  2463.     >>
  2464.  
  2465.     dontdraw not {//renlinear exec} if
  2466.  
  2467.     end
  2468.  
  2469. } bind def
  2470. % --END ENCODER rsslimited--
  2471.  
  2472. % --BEGIN ENCODER rssexpanded--
  2473. % --DESC: Reduced Space Symbology Expanded (RSS-Expanded)
  2474. % --EXAM: 000000010011001010100001000000010000
  2475. % --EXOP: height=0.3
  2476. % --RNDR: renlinear
  2477. /rssexpanded {
  2478.  
  2479.     1 dict begin            % Confine variables to local scope
  2480.  
  2481.     /options exch def  % We are given an option string
  2482.     /barcode exch def  % We are given a barcode string
  2483.  
  2484.     /dontdraw false def
  2485.     /height 1 def
  2486.     
  2487.     % Parse the input options
  2488.     options type /stringtype eq {
  2489.         1 dict begin
  2490.         options {
  2491.             token false eq {exit} if dup length string cvs (=) search
  2492.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  2493.         } loop
  2494.         currentdict end /options exch def
  2495.     } if
  2496.     options {def} forall
  2497.  
  2498.     /height height cvr def
  2499.  
  2500.     /ncr {  % n r
  2501.         2 copy sub 2 copy lt {exch} if  % n r maxd mind
  2502.         1 1 5 3 roll  % mind j=1 v=1 n maxd
  2503.         1 add -1 exch {  % mind j v  n -1 maxd+1
  2504.             mul  % mind j v*i
  2505.             1 index 3 index le {
  2506.                 1 index idiv exch 1 add exch
  2507.             } if
  2508.         } for
  2509.         {  % mind j v
  2510.             1 index 3 index gt {exit} if
  2511.             1 index idiv exch 1 add exch
  2512.         } loop
  2513.         exch pop exch pop
  2514.     } bind def
  2515.     
  2516.     /getRSSwidths {
  2517.         /oe exch def
  2518.         /el exch def
  2519.         /mw exch def
  2520.         /nm exch def
  2521.         /val exch def
  2522.         /out el array def
  2523.         /mask 0 def
  2524.         0 1 el 2 sub {
  2525.             /bar exch def
  2526.             /ew 1 def 
  2527.             /mask mask 1 bar bitshift or def {
  2528.                 /sval nm ew sub 1 sub el bar sub 2 sub ncr def
  2529.                 oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and {
  2530.                     /sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def
  2531.                 } if
  2532.                 el bar sub 2 gt {
  2533.                     /lval 0 def
  2534.                     nm ew sub el sub bar add 2 add -1 mw 1 add {
  2535.                         nm exch sub ew sub 1 sub el bar sub 3 sub ncr
  2536.                         /lval exch lval add def
  2537.                     } for
  2538.                     /sval sval lval el bar sub 1 sub mul sub def
  2539.                 } {
  2540.                     nm ew sub mw gt {/sval sval 1 sub def} if
  2541.                 } ifelse
  2542.                 /val val sval sub def
  2543.                 val 0 lt {exit} if
  2544.                 /ew ew 1 add def
  2545.                 /mask mask 1 bar bitshift not and def
  2546.             } loop  
  2547.             /val val sval add def
  2548.             /nm nm ew sub def
  2549.             out bar ew put 
  2550.         } for
  2551.         out el 1 sub nm put
  2552.         out
  2553.     } bind def
  2554.  
  2555.     /binval [barcode {48 sub} forall] def
  2556.     /datalen binval length 12 idiv def
  2557.     
  2558.     /tab174 [
  2559.         347   0     12 5   7 2  87  4
  2560.         1387  348   10 7   5 4  52  20
  2561.         2947  1388  8  9   4 5  30  52
  2562.         3987  2948  6  11  3 6  10  104
  2563.         4191  3988  4  13  1 8  1   204
  2564.     ] def
  2565.  
  2566.     /dxw datalen array def
  2567.     
  2568.     0 1 datalen 1 sub {
  2569.  
  2570.         /x exch def
  2571.  
  2572.         /d binval x 12 mul 12 getinterval def
  2573.         /d 0 0 1 11 {/j exch def 2 11 j sub exp cvi d j get mul add} for def
  2574.  
  2575.         /j 0 def {
  2576.             d tab174 j get le {
  2577.                 tab174 j 1 add 7 getinterval {} forall
  2578.                 /dte exch def /dto exch def
  2579.                 /dmwe exch def /dmwo exch def
  2580.                 /dele exch def /delo exch def
  2581.                 /dgs exch def
  2582.                 exit
  2583.             } if
  2584.             /j j 8 add def
  2585.         } loop
  2586.  
  2587.         /dwo d dgs sub dte idiv delo dmwo 4 true  getRSSwidths def
  2588.         /dwe d dgs sub dte mod  dele dmwe 4 false getRSSwidths def
  2589.  
  2590.         /dw 8 array def        
  2591.         x 2 mod 0 eq {                    
  2592.             0 1 3 {
  2593.                 /j exch def
  2594.                 dw 7 j 2 mul sub dwo j get put
  2595.                 dw 6 j 2 mul sub dwe j get put
  2596.             } for
  2597.         } {           
  2598.             0 1 3 {
  2599.                 /j exch def
  2600.                 dw j 2 mul dwo j get put
  2601.                 dw j 2 mul 1 add dwe j get put
  2602.             } for
  2603.         } ifelse
  2604.  
  2605.         dxw x dw put
  2606.  
  2607.     } for
  2608.     
  2609.     /widths [
  2610.         dxw {{} forall} forall
  2611.     ] def
  2612.  
  2613.     /checkweights [
  2614.         77   96   32   81   27   9    3    1
  2615.         20   60   180  118  143  7    21   63
  2616.         205  209  140  117  39   13   145  189
  2617.         193  157  49   147  19   57   171  91
  2618.         132  44   85   169  197  136  186  62
  2619.         185  133  188  142  4    12   36   108
  2620.         50   87   29   80   97   173  128  113
  2621.         150  28   84   41   123  158  52   156
  2622.         166  196  206  139  187  203  138  46
  2623.         76   17   51   153  37   111  122  155
  2624.         146  119  110  107  106  176  129  43
  2625.         16   48   144  10   30   90   59   177
  2626.         164  125  112  178  200  137  116  109
  2627.         70   210  208  202  184  130  179  115
  2628.         190  204  68   93   31   151  191  134
  2629.         148  22   66   198  172  94   71   2
  2630.         40   154  192  64   162  54   18   6
  2631.         120  149  25   75   14   42   126  167
  2632.         175  199  207  69   23   78   26   79
  2633.         103  98   83   38   114  131  182  124
  2634.         159  53   88   170  127  183  61   161
  2635.         55   165  73   8    24   72   5    15
  2636.         89   100  174  58   160  194  135  45
  2637.     ] def
  2638.     
  2639.     /checksum 0 def
  2640.     0 1 widths length 1 sub {
  2641.         /i exch def
  2642.         /checksum checksum widths i get checkweights i get mul add def 
  2643.     } for
  2644.     /checksum checksum 211 mod datalen 3 sub 211 mul add def
  2645.  
  2646.     /i 0 def {
  2647.         checksum tab174 i get le {
  2648.             tab174 i 1 add 7 getinterval {} forall
  2649.             /cte exch def /cto exch def
  2650.             /cmwe exch def /cmwo exch def
  2651.             /cele exch def /celo exch def
  2652.             /cgs exch def
  2653.             exit
  2654.         } if
  2655.         /i i 8 add def
  2656.     } loop
  2657.  
  2658.     /cwo checksum cgs sub cte idiv celo cmwo 4 true  getRSSwidths def
  2659.     /cwe checksum cgs sub cte mod  cele cmwe 4 false getRSSwidths def
  2660.     
  2661.     /cw 8 array def        
  2662.     0 1 3 {
  2663.         /i exch def
  2664.         cw i 2 mul cwo i get put
  2665.         cw i 2 mul 1 add cwe i get put
  2666.     } for
  2667.     
  2668.     /finderwidths [
  2669.         1 8 4 1 1    1 1 4 8 1
  2670.         3 6 4 1 1    1 1 4 6 3
  2671.         3 4 6 1 1    1 1 6 4 3
  2672.         3 2 8 1 1    1 1 8 2 3
  2673.         2 6 5 1 1    1 1 5 6 2
  2674.         2 2 9 1 1    1 1 9 2 2
  2675.     ] def
  2676.  
  2677.     /finderseq [
  2678.         [0 1]
  2679.         [0 3 2]
  2680.         [0 5 2 7]
  2681.         [0 9 2 7 4]
  2682.         [0 9 2 7 6 11]
  2683.         [0 9 2 7 8 11 10]
  2684.         [0 1 2 3 4 5 6 7]
  2685.         [0 1 2 3 4 5 6 9 8]
  2686.         [0 1 2 3 4 5 6 9 10 11]
  2687.         [0 1 2 3 4 7 6 9 8 11 10]
  2688.     ] def
  2689.  
  2690.     /seq finderseq datalen 2 add 2 idiv 2 sub get def
  2691.     /fxw seq length array def
  2692.     0 1 seq length 1 sub {
  2693.         /x exch def
  2694.         fxw x finderwidths seq x get 5 mul 5 getinterval put
  2695.     } for
  2696.     
  2697.     /sbs [
  2698.         1
  2699.         cw {} forall
  2700.         0 1 datalen 1 sub {
  2701.             /i exch def
  2702.             i 2 mod 0 eq {fxw i 2 idiv get {} forall} if
  2703.             dxw i get {} forall
  2704.         } for
  2705.         1 1
  2706.     ] def
  2707.     
  2708.     % Return the arguments
  2709.     <<
  2710.     /ren (renlinear)
  2711.     /sbs sbs
  2712.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  2713.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  2714.     /opt options
  2715.     >>
  2716.  
  2717.     dontdraw not {//renlinear exec} if
  2718.  
  2719.     end
  2720.  
  2721. } bind def
  2722. % --END ENCODER rssexpanded--
  2723.  
  2724. % --BEGIN ENCODER pharmacode--
  2725. % --DESC: Pharmaceutical Binary Code
  2726. % --EXAM: 117480
  2727. % --EXOP: showborder
  2728. % --RNDR: renlinear
  2729. /pharmacode {
  2730.  
  2731.     1 dict begin                 % Confine variables to local scope
  2732.  
  2733.     /options exch def       % We are given an option string
  2734.     /barcode exch def       % We are given a barcode string
  2735.  
  2736.     /dontdraw false def
  2737.     /height 8 2.835 mul 72 div def
  2738.     /nwidth 0.5 2.835 mul def
  2739.     /wwidth 1.5 2.835 mul def
  2740.     /swidth 1.0 2.835 mul def    
  2741.  
  2742.     % Parse the input options
  2743.     options type /stringtype eq {
  2744.         1 dict begin
  2745.         options {
  2746.             token false eq {exit} if dup length string cvs (=) search
  2747.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  2748.         } loop
  2749.         currentdict end /options exch def
  2750.     } if
  2751.     options {def} forall
  2752.  
  2753.     /height height cvr def
  2754.     /nwidth nwidth cvr def
  2755.     /wwidth wwidth cvr def
  2756.     /swidth swidth cvr def
  2757.  
  2758.     % Create the human readable text
  2759.     /txt barcode length array def
  2760.     0 1 barcode length 1 sub {
  2761.         /i exch def
  2762.         txt i [barcode i 1 getinterval 0 0 () 0] put
  2763.     } for
  2764.  
  2765.     % Convert the integer into the paramacode string 
  2766.     /barcode barcode cvi 1 add 2 17 string cvrs def
  2767.     /barcode barcode 1 barcode length 1 sub getinterval def
  2768.  
  2769.     /barlen barcode length def  % Length of the code
  2770.     /sbs barlen 2 mul array def
  2771.  
  2772.     0 1 barlen 1 sub {
  2773.         /i exch def
  2774.         /enc barcode i 1 getinterval def
  2775.         enc (0) eq {
  2776.             sbs i 2 mul nwidth put
  2777.         } {
  2778.             sbs i 2 mul wwidth put
  2779.         } ifelse
  2780.         sbs i 2 mul 1 add swidth put
  2781.     } for
  2782.  
  2783.     % Return the arguments
  2784.     <<
  2785.     /ren (renlinear)
  2786.     /sbs sbs
  2787.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  2788.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  2789.     /txt txt
  2790.     /textxalign (center)
  2791.     /opt options
  2792.     >>
  2793.  
  2794.     dontdraw not {//renlinear exec} if
  2795.  
  2796.     end
  2797.  
  2798. } bind def
  2799. % --END ENCODER pharmacode--
  2800.  
  2801. % --BEGIN ENCODER code2of5--
  2802. % --DESC: Code 25
  2803. % --EXAM: 01234567
  2804. % --EXOP: includetext includecheck includecheckintext
  2805. % --RNDR: renlinear
  2806. /code2of5 {
  2807.  
  2808.     % Thanks to Michael Landers
  2809.  
  2810.     1 dict begin                 % Confine variable to local scope
  2811.  
  2812.     /options exch def       % We are given an option string
  2813.     /barcode exch def       % We are given a barcode string
  2814.  
  2815.     /dontdraw false def
  2816.     /includecheck false def
  2817.     /includetext false def   % Enable/disable text
  2818.     /includecheckintext false def
  2819.     /textfont /Courier def
  2820.     /textsize 10 def
  2821.     /textyoffset -7 def
  2822.     /height 1 def
  2823.     
  2824.     % Parse the input options
  2825.     options type /stringtype eq {
  2826.         1 dict begin
  2827.         options {
  2828.             token false eq {exit} if dup length string cvs (=) search
  2829.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  2830.         } loop
  2831.         currentdict end /options exch def
  2832.     } if
  2833.     options {def} forall
  2834.     
  2835.     /textfont textfont cvlit def
  2836.     /textsize textsize cvr def
  2837.     /textyoffset textyoffset cvr def
  2838.     /height height cvr def
  2839.     
  2840.     % Create an array containing the character mappings
  2841.     /encs
  2842.     [ (1111313111) (3111111131) (1131111131) (3131111111)
  2843.       (1111311131) (3111311111) (1131311111) (1111113131)
  2844.       (3111113111) (1131113111) (313111) (311131)
  2845.     ] def
  2846.  
  2847.     % Create a string of the available characters
  2848.     /barchars (0123456789) def
  2849.  
  2850.     /barlen barcode length def            % Length of the code
  2851.  
  2852.     includecheck {
  2853.         /sbs barlen 10 mul 22 add string def
  2854.         /txt barlen 1 add array def
  2855.     } {
  2856.         /sbs barlen 10 mul 12 add string def
  2857.         /txt barlen array def
  2858.     } ifelse
  2859.     
  2860.     % Put the start character
  2861.     sbs 0 encs 10 get putinterval
  2862.  
  2863.     /checksum 0 def
  2864.     
  2865.     0 1 barlen 1 sub {
  2866.         /i exch def
  2867.         % Lookup the encoding for the each barcode character
  2868.         barcode i 1 getinterval barchars exch search
  2869.         pop                                 % Discard true leaving pre
  2870.         length /indx exch def               % indx is the length of pre
  2871.         pop pop                             % Discard seek and post
  2872.         /enc encs indx get def              % Get the indxth encoding
  2873.         sbs i 10 mul 6 add enc putinterval  % Put encoded digit into sbs
  2874.         txt i [barcode i 1 getinterval i 14 mul 10 add textyoffset textfont textsize] put
  2875.         barlen i sub 2 mod 0 eq {
  2876.             /checksum checksum indx add def
  2877.         } {            
  2878.             /checksum checksum indx 3 mul add def
  2879.         } ifelse        
  2880.     } for
  2881.     
  2882.     % Put the checksum and end characters
  2883.     includecheck {
  2884.         /checksum 10 checksum 10 mod sub 10 mod def
  2885.         sbs barlen 10 mul 6 add encs checksum get putinterval
  2886.         sbs barlen 10 mul 16 add encs 11 get putinterval
  2887.         includecheckintext {
  2888.             txt barlen [barchars checksum 1 getinterval barlen 14 mul 10 add textyoffset textfont textsize] put
  2889.         } {            
  2890.             txt barlen [( ) barlen 14 mul 10 add textyoffset textfont textsize] put
  2891.         } ifelse
  2892.     } {
  2893.         sbs barlen 10 mul 6 add encs 11 get putinterval
  2894.     } ifelse
  2895.     
  2896.     % Return the arguments
  2897.     <<
  2898.     /ren (renlinear)
  2899.     /sbs [sbs {48 sub} forall]
  2900.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  2901.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  2902.     includetext {
  2903.         /txt txt
  2904.     } if
  2905.     /opt options
  2906.     >>
  2907.  
  2908.     dontdraw not {//renlinear exec} if
  2909.  
  2910.     end
  2911.  
  2912. } bind def
  2913. % --END ENCODER code2of5--
  2914.  
  2915. % --BEGIN ENCODER code11--
  2916. % --DESC: Code 11
  2917. % --EXAM: 0123456789
  2918. % --EXOP: includetext includecheck includecheckintext
  2919. % --RNDR: renlinear
  2920. /code11 {
  2921.  
  2922.     1 dict begin            % Confine variables to local scope
  2923.  
  2924.     /options exch def  % We are given an option string
  2925.     /barcode exch def  % We are given a barcode string
  2926.  
  2927.     /dontdraw false def
  2928.     /includecheck false def
  2929.     /includetext false def
  2930.     /includecheckintext false def
  2931.     /textfont /Courier def
  2932.     /textsize 10 def
  2933.     /textyoffset -7 def
  2934.     /height 1 def
  2935.     
  2936.     % Parse the input options
  2937.     options type /stringtype eq {
  2938.         1 dict begin
  2939.         options {
  2940.             token false eq {exit} if dup length string cvs (=) search
  2941.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  2942.         } loop
  2943.         currentdict end /options exch def
  2944.     } if
  2945.     options {def} forall
  2946.  
  2947.     /textfont textfont cvlit def
  2948.     /textsize textsize cvr def
  2949.     /textyoffset textyoffset cvr def
  2950.     /height height cvr def
  2951.     
  2952.     % Create an array containing the character mappings
  2953.     /encs
  2954.     [ (111131) (311131) (131131) (331111) (113131)
  2955.       (313111) (133111) (111331) (311311) (311111)
  2956.       (113111) (113311)
  2957.     ] def
  2958.  
  2959.     % Create a string of the available characters
  2960.     /barchars (0123456789-) def
  2961.  
  2962.     /barlen barcode length def        % Length of the code
  2963.  
  2964.     includecheck {
  2965.         barlen 10 ge {
  2966.             /sbs barlen 6 mul 24 add string def
  2967.             /txt barlen 2 add array def
  2968.         } {
  2969.             /sbs barlen 6 mul 18 add string def
  2970.             /txt barlen 1 add array def
  2971.         } ifelse
  2972.     } {
  2973.         /sbs barlen 6 mul 12 add string def
  2974.         /txt barlen array def
  2975.     } ifelse
  2976.  
  2977.     % Put the start character
  2978.     sbs 0 encs 10 get putinterval
  2979.  
  2980.     /checksum1 0 def /checksum2 0 def
  2981.     
  2982.     /xpos 8 def
  2983.     0 1 barlen 1 sub {
  2984.         /i exch def
  2985.         % Lookup the encoding for the each barcode character
  2986.         barcode i 1 getinterval barchars exch search
  2987.         pop                                % Discard true leaving pre
  2988.         length /indx exch def              % indx is the length of pre
  2989.         pop pop                            % Discard seek and post
  2990.         /enc encs indx get def             % Get the indxth encoding
  2991.         sbs i 6 mul 6 add enc putinterval  % Put encoded digit into sbs
  2992.         txt i [barcode i 1 getinterval xpos textyoffset textfont textsize] put
  2993.         0 1 5 {       % xpos+=width of the character
  2994.             /xpos exch enc exch get 48 sub xpos add def
  2995.         } for
  2996.         /checksum1 checksum1 barlen i sub 1 sub 10 mod 1 add indx mul add def
  2997.         /checksum2 checksum2 barlen i sub 9 mod 1 add indx mul add def
  2998.     } for
  2999.    
  3000.     % Put the checksum and end characters
  3001.     includecheck {
  3002.         /checksum1 checksum1 11 mod def        
  3003.         barlen 10 ge {
  3004.             /checksum2 checksum2 checksum1 add 11 mod def
  3005.             sbs barlen 6 mul 6 add encs checksum1 get putinterval        
  3006.             sbs barlen 6 mul 12 add encs checksum2 get putinterval
  3007.             includecheckintext {
  3008.                 txt barlen [barchars checksum1 1 getinterval xpos textyoffset textfont textsize] put
  3009.                 /enc encs checksum1 get def   
  3010.                 0 1 5 {       % xpos+=width of the character
  3011.                     /xpos exch enc exch get 48 sub xpos add def
  3012.                 } for
  3013.                 txt barlen 1 add [barchars checksum2 1 getinterval xpos textyoffset textfont textsize] put
  3014.             } {
  3015.                 txt barlen [() xpos textyoffset textfont textsize] put
  3016.                 txt barlen 1 add [() xpos textyoffset textfont textsize] put
  3017.             } ifelse
  3018.             sbs barlen 6 mul 18 add encs 11 get putinterval
  3019.         } {
  3020.             sbs barlen 6 mul 6 add encs checksum1 get putinterval          
  3021.             includecheckintext {
  3022.                 txt barlen [barchars checksum1 1 getinterval xpos textyoffset textfont textsize] put
  3023.             } {
  3024.                 txt barlen [() xpos textyoffset textfont textsize] put
  3025.             } ifelse
  3026.             sbs barlen 6 mul 12 add encs 11 get putinterval
  3027.         } ifelse
  3028.     } {
  3029.         sbs barlen 6 mul 6 add encs 11 get putinterval
  3030.     } ifelse
  3031.  
  3032.     % Return the arguments
  3033.     <<
  3034.     /ren (renlinear)
  3035.     /sbs [sbs {48 sub} forall]
  3036.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  3037.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  3038.     includetext {
  3039.         /txt txt
  3040.     } if
  3041.     /opt options
  3042.     >>
  3043.  
  3044.     dontdraw not {//renlinear exec} if
  3045.  
  3046.     end
  3047.  
  3048. } bind def
  3049. % --END ENCODER code11--
  3050.  
  3051. % --BEGIN ENCODER rationalizedCodabar--
  3052. % --DESC: Rationalized Codabar
  3053. % --EXAM: A0123456789B
  3054. % --EXOP: includetext includecheck includecheckintext
  3055. % --RNDR: renlinear
  3056. /rationalizedCodabar {
  3057.  
  3058.     1 dict begin                    % Confine variables to local scope
  3059.  
  3060.     /options exch def          % We are given an option string
  3061.     /barcode exch def          % We are given a barcode string
  3062.  
  3063.     /dontdraw false def
  3064.     /includecheck false def     % Enable/disable checkdigit
  3065.     /includetext false def      % Enable/disable text
  3066.     /includecheckintext false def
  3067.     /textfont /Courier def
  3068.     /textsize 10 def
  3069.     /textyoffset -7 def
  3070.     /height 1 def
  3071.     
  3072.     % Parse the input options
  3073.     options type /stringtype eq {
  3074.         1 dict begin
  3075.         options {
  3076.             token false eq {exit} if dup length string cvs (=) search
  3077.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  3078.         } loop
  3079.         currentdict end /options exch def
  3080.     } if
  3081.     options {def} forall
  3082.     
  3083.     /textfont textfont cvlit def
  3084.     /textsize textsize cvr def
  3085.     /textyoffset textyoffset cvr def
  3086.     /height height cvr def
  3087.     
  3088.     % Create an array containing the character mappings
  3089.     /encs
  3090.     [ (11111331) (11113311) (11131131) (33111111) (11311311)
  3091.       (31111311) (13111131) (13113111) (13311111) (31131111)
  3092.       (11133111) (11331111) (31113131) (31311131) (31313111)
  3093.       (11313131) (11331311) (13131131) (11131331) (11133311)
  3094.     ] def
  3095.  
  3096.     % Create a string of the available characters
  3097.     /barchars (0123456789-$:/.+ABCD) def
  3098.  
  3099.     /barlen barcode length def    % Length of the code
  3100.  
  3101.     includecheck {
  3102.         /sbs barlen 8 mul 8 add string def
  3103.         /txt barlen 1 add array def
  3104.     } {
  3105.         /sbs barlen 8 mul string def
  3106.         /txt barlen array def
  3107.     } ifelse
  3108.  
  3109.     /checksum 0 def
  3110.     /xpos 0 def
  3111.     0 1 barlen 2 sub {
  3112.         /i exch def
  3113.         % Lookup the encoding for the each barcode character
  3114.         barcode i 1 getinterval barchars exch search
  3115.         pop                          % Discard true leaving pre
  3116.         length /indx exch def        % indx is the length of pre
  3117.         pop pop                      % Discard seek and post
  3118.         /enc encs indx get def       % Get the indxth encoding
  3119.         sbs i 8 mul enc putinterval  % Put encoded digit into sbs
  3120.         txt i [barcode i 1 getinterval xpos textyoffset textfont textsize] put
  3121.         0 1 7 {       % xpos+=width of the character
  3122.             /xpos exch enc exch get 48 sub xpos add def
  3123.         } for
  3124.         /checksum checksum indx add def
  3125.     } for
  3126.  
  3127.     % Find index of last character
  3128.     barcode barlen 1 sub 1 getinterval barchars exch search
  3129.     pop                          % Discard true leaving pre
  3130.     length /indx exch def        % indx is the length of pre
  3131.     pop pop                      % Discard seek and post
  3132.  
  3133.     includecheck {
  3134.         % Put the checksum character
  3135.         /checksum checksum indx add def
  3136.         /checksum 16 checksum 16 mod sub 16 mod def
  3137.         sbs barlen 8 mul 8 sub encs checksum get putinterval
  3138.         includecheckintext {
  3139.             txt barlen 1 sub [barchars checksum 1 getinterval xpos textyoffset textfont textsize] put
  3140.         } {
  3141.             txt barlen 1 sub [( ) xpos textyoffset textfont textsize] put
  3142.         } ifelse
  3143.         0 1 7 {       % xpos+=width of the character
  3144.             /xpos exch encs checksum get exch get 48 sub xpos add def
  3145.         } for
  3146.         % Put the end character
  3147.         /enc encs indx get def            % Get the indxth encoding
  3148.         sbs barlen 8 mul enc putinterval  % Put encoded digit into sbs
  3149.         txt barlen [barcode barlen 1 sub 1 getinterval xpos textyoffset textfont textsize] put
  3150.     } {
  3151.         % Put the end character
  3152.         /enc encs indx get def                  % Get the indxth encoding
  3153.         sbs barlen 8 mul 8 sub enc putinterval  % Put encoded digit into sbs
  3154.         txt barlen 1 sub [barcode barlen 1 sub 1 getinterval xpos textyoffset textfont textsize] put
  3155.     } ifelse
  3156.  
  3157.     % Return the arguments
  3158.     <<
  3159.     /ren (renlinear)
  3160.     /sbs [sbs {48 sub} forall]
  3161.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  3162.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  3163.     includetext {
  3164.         /txt txt
  3165.     } if
  3166.     /opt options
  3167.     >>
  3168.  
  3169.     dontdraw not {//renlinear exec} if
  3170.  
  3171.     end
  3172.  
  3173. } bind def
  3174. % --END ENCODER rationalizedCodabar--
  3175.  
  3176. % --BEGIN ENCODER onecode--
  3177. % --DESC: United States Postal Service OneCode
  3178. % --EXAM: 0123456709498765432101234567891
  3179. % --EXOP: barcolor=FF0000
  3180. % --RNDR: renlinear
  3181. /onecode {
  3182.  
  3183.     1 dict begin
  3184.  
  3185.     /options exch def              % We are given an option string
  3186.     /barcode exch def              % We are given a barcode string
  3187.  
  3188.     /dontdraw false def
  3189.     /height 0.175 def
  3190.     
  3191.     % Parse the input options
  3192.     options type /stringtype eq {
  3193.         1 dict begin
  3194.         options {
  3195.             token false eq {exit} if dup length string cvs (=) search
  3196.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  3197.         } loop
  3198.         currentdict end /options exch def
  3199.     } if
  3200.     options {def} forall
  3201.  
  3202.     /height height cvr def
  3203.  
  3204.     /barlen barcode length def
  3205.  
  3206.     % Create the human readable text
  3207.     /txt barcode length array def
  3208.     0 1 barcode length 1 sub {
  3209.         /i exch def
  3210.         txt i [barcode i 1 getinterval 0 0 () 0] put
  3211.     } for
  3212.  
  3213.     /normalize {
  3214.         /base exch def
  3215.         /num exch def
  3216.         num length 1 sub -1 1 {
  3217.             /i exch def        
  3218.             num i 1 sub 2 copy get num i get base idiv add put
  3219.             num i num i get base mod put
  3220.         } for
  3221.         { %loop - extend input as necessary
  3222.             num 0 get base lt {exit} if
  3223.             /num [0 num {} forall] def        
  3224.             num 0 num 0 get num 1 get base idiv add put
  3225.             num 1 num 1 get base mod put
  3226.         } loop
  3227.         % Trim leading zeros
  3228.         /num [/i true def num {dup 0 eq i and {pop} {/i false def} ifelse} forall] def   
  3229.         num length 0 eq {/num [0] def} if
  3230.         num
  3231.     } bind def
  3232.  
  3233.     /bigadd {
  3234.         2 copy length exch length
  3235.         2 copy sub abs /offset exch def
  3236.         lt {exch} if
  3237.         /a exch def /b exch def    
  3238.         0 1 b length 1 sub {
  3239.             dup a exch offset add 2 copy get b 5 -1 roll get add put
  3240.         } for
  3241.         a
  3242.     } bind def
  3243.  
  3244.     % Conversion of data fields into binary data
  3245.     barlen 20 eq {[0]} if
  3246.     barlen 25 eq {[1]} if
  3247.     barlen 29 eq {[1 0 0 0 0 1]} if
  3248.     barlen 31 eq {[1 0 0 0 1 0 0 0 0 1]} if
  3249.     /binval exch [barcode 20 barlen 20 sub getinterval {48 sub} forall] bigadd def
  3250.     /binval [binval {} forall barcode 0 get 48 sub] def
  3251.     /binval [binval {5 mul} forall] [barcode 1 get 48 sub] bigadd 10 normalize def
  3252.     /binval [binval {} forall barcode 2 18 getinterval {48 sub} forall] def
  3253.  
  3254.     % Conversion of binary data into byte array
  3255.     /bytes 13 array def
  3256.     /bintmp [binval {} forall] def
  3257.     12 -1 0 {
  3258.         /i exch def
  3259.         0 1 bintmp length 2 sub {
  3260.             /j exch def
  3261.             bintmp j 1 add 2 copy get bintmp j get 256 mod 10 mul add put
  3262.             bintmp j bintmp j get 256 idiv put
  3263.         } for
  3264.         bytes i bintmp bintmp length 1 sub get 256 mod put
  3265.         bintmp bintmp length 1 sub 2 copy get 256 idiv put    
  3266.     } for
  3267.  
  3268.     % Generation of 11-bit CRC on byte array
  3269.     /fcs 2047 def
  3270.     /dat bytes 0 get 5 bitshift def
  3271.     6 {
  3272.         fcs dat xor 1024 and 0 ne {
  3273.             /fcs fcs 1 bitshift 3893 xor def 
  3274.         } {
  3275.             /fcs fcs 1 bitshift def
  3276.         } ifelse
  3277.         /fcs fcs 2047 and def
  3278.         /dat dat 1 bitshift def
  3279.     } repeat
  3280.     1 1 12 {
  3281.         bytes exch get 3 bitshift /dat exch def    
  3282.         8 {        
  3283.             fcs dat xor 1024 and 0 ne {
  3284.                 /fcs fcs 1 bitshift 3893 xor def 
  3285.             } {
  3286.                 /fcs fcs 1 bitshift def
  3287.             } ifelse
  3288.             /fcs fcs 2047 and def
  3289.             /dat dat 1 bitshift def
  3290.         } repeat
  3291.     } for
  3292.  
  3293.     % Conversion from binary data to codewords
  3294.     /codewords 10 array def
  3295.     9 -1 0 {
  3296.         /i exch def
  3297.         i 9 eq {
  3298.             /b 636 def
  3299.         } {
  3300.             /b 1365 def
  3301.         } ifelse
  3302.         0 1 binval length 2 sub {
  3303.             /j exch def
  3304.             binval j 1 add 2 copy get binval j get b mod 10 mul add put
  3305.             binval j binval j get b idiv put
  3306.         } for   
  3307.         codewords i binval binval length 1 sub get b mod put
  3308.         binval binval length 1 sub 2 copy get b idiv put
  3309.     } for
  3310.  
  3311.     % Inserting additional information into codewords
  3312.     codewords 9 codewords 9 get 2 mul put
  3313.     fcs 1024 and 0 ne {
  3314.         codewords 0 codewords 0 get 659 add put
  3315.     } if
  3316.  
  3317.     % Conversion from codewords to characters
  3318.     /tab513 [
  3319.         31 7936   47 7808   55 7552   59 7040   61 6016   62 3968   79 7744   87 
  3320.       7488   91 6976   93 5952   94 3904  103 7360  107 6848  109 5824  110 3776 
  3321.        115 6592  117 5568  118 3520  121 5056  122 3008  124 1984  143 7712  151 
  3322.       7456  155 6944  157 5920  158 3872  167 7328  171 6816  173 5792  174 3744 
  3323.        179 6560  181 5536  182 3488  185 5024  186 2976  188 1952  199 7264  203 
  3324.       6752  205 5728  206 3680  211 6496  213 5472  214 3424  217 4960  218 2912 
  3325.        220 1888  227 6368  229 5344  230 3296  233 4832  234 2784  236 1760  241 
  3326.       4576  242 2528  244 1504  248  992  271 7696  279 7440  283 6928  285 5904 
  3327.        286 3856  295 7312  299 6800  301 5776  302 3728  307 6544  309 5520  310 
  3328.       3472  313 5008  314 2960  316 1936  327 7248  331 6736  333 5712  334 3664 
  3329.        339 6480  341 5456  342 3408  345 4944  346 2896  348 1872  355 6352  357 
  3330.       5328  358 3280  361 4816  362 2768  364 1744  369 4560  370 2512  372 1488 
  3331.        376  976  391 7216  395 6704  397 5680  398 3632  403 6448  405 5424  406 
  3332.       3376  409 4912  410 2864  412 1840  419 6320  421 5296  422 3248  425 4784 
  3333.        426 2736  428 1712  433 4528  434 2480  436 1456  440  944  451 6256  453 
  3334.       5232  454 3184  457 4720  458 2672  460 1648  465 4464  466 2416  468 1392 
  3335.        472  880  481 4336  482 2288  484 1264  488  752  527 7688  535 7432  539 
  3336.       6920  541 5896  542 3848  551 7304  555 6792  557 5768  558 3720  563 6536 
  3337.        565 5512  566 3464  569 5000  570 2952  572 1928  583 7240  587 6728  589 
  3338.       5704  590 3656  595 6472  597 5448  598 3400  601 4936  602 2888  604 1864 
  3339.        611 6344  613 5320  614 3272  617 4808  618 2760  620 1736  625 4552  626 
  3340.       2504  628 1480  632  968  647 7208  651 6696  653 5672  654 3624  659 6440 
  3341.        661 5416  662 3368  665 4904  666 2856  668 1832  675 6312  677 5288  678 
  3342.       3240  681 4776  682 2728  684 1704  689 4520  690 2472  692 1448  696  936 
  3343.        707 6248  709 5224  710 3176  713 4712  714 2664  716 1640  721 4456  722 
  3344.       2408  724 1384  728  872  737 4328  738 2280  740 1256  775 7192  779 6680 
  3345.        781 5656  782 3608  787 6424  789 5400  790 3352  793 4888  794 2840  796 
  3346.       1816  803 6296  805 5272  806 3224  809 4760  810 2712  812 1688  817 4504 
  3347.        818 2456  820 1432  824  920  835 6232  837 5208  838 3160  841 4696  842 
  3348.       2648  844 1624  849 4440  850 2392  852 1368  865 4312  866 2264  868 1240 
  3349.        899 6200  901 5176  902 3128  905 4664  906 2616  908 1592  913 4408  914 
  3350.       2360  916 1336  929 4280  930 2232  932 1208  961 4216  962 2168  964 1144 
  3351.       1039 7684 1047 7428 1051 6916 1053 5892 1054 3844 1063 7300 1067 6788 1069 
  3352.       5764 1070 3716 1075 6532 1077 5508 1078 3460 1081 4996 1082 2948 1084 1924 
  3353.       1095 7236 1099 6724 1101 5700 1102 3652 1107 6468 1109 5444 1110 3396 1113 
  3354.       4932 1114 2884 1116 1860 1123 6340 1125 5316 1126 3268 1129 4804 1130 2756 
  3355.       1132 1732 1137 4548 1138 2500 1140 1476 1159 7204 1163 6692 1165 5668 1166 
  3356.       3620 1171 6436 1173 5412 1174 3364 1177 4900 1178 2852 1180 1828 1187 6308 
  3357.       1189 5284 1190 3236 1193 4772 1194 2724 1196 1700 1201 4516 1202 2468 1204 
  3358.       1444 1219 6244 1221 5220 1222 3172 1225 4708 1226 2660 1228 1636 1233 4452 
  3359.       1234 2404 1236 1380 1249 4324 1250 2276 1287 7188 1291 6676 1293 5652 1294 
  3360.       3604 1299 6420 1301 5396 1302 3348 1305 4884 1306 2836 1308 1812 1315 6292 
  3361.       1317 5268 1318 3220 1321 4756 1322 2708 1324 1684 1329 4500 1330 2452 1332 
  3362.       1428 1347 6228 1349 5204 1350 3156 1353 4692 1354 2644 1356 1620 1361 4436 
  3363.       1362 2388 1377 4308 1378 2260 1411 6196 1413 5172 1414 3124 1417 4660 1418 
  3364.       2612 1420 1588 1425 4404 1426 2356 1441 4276 1442 2228 1473 4212 1474 2164 
  3365.       1543 7180 1547 6668 1549 5644 1550 3596 1555 6412 1557 5388 1558 3340 1561 
  3366.       4876 1562 2828 1564 1804 1571 6284 1573 5260 1574 3212 1577 4748 1578 2700 
  3367.       1580 1676 1585 4492 1586 2444 1603 6220 1605 5196 1606 3148 1609 4684 1610 
  3368.       2636 1617 4428 1618 2380 1633 4300 1634 2252 1667 6188 1669 5164 1670 3116 
  3369.       1673 4652 1674 2604 1681 4396 1682 2348 1697 4268 1698 2220 1729 4204 1730 
  3370.       2156 1795 6172 1797 5148 1798 3100 1801 4636 1802 2588 1809 4380 1810 2332 
  3371.       1825 4252 1826 2204 1857 4188 1858 2140 1921 4156 1922 2108 2063 7682 2071 
  3372.       7426 2075 6914 2077 5890 2078 3842 2087 7298 2091 6786 2093 5762 2094 3714 
  3373.       2099 6530 2101 5506 2102 3458 2105 4994 2106 2946 2119 7234 2123 6722 2125 
  3374.       5698 2126 3650 2131 6466 2133 5442 2134 3394 2137 4930 2138 2882 2147 6338 
  3375.       2149 5314 2150 3266 2153 4802 2154 2754 2161 4546 2162 2498 2183 7202 2187 
  3376.       6690 2189 5666 2190 3618 2195 6434 2197 5410 2198 3362 2201 4898 2202 2850 
  3377.       2211 6306 2213 5282 2214 3234 2217 4770 2218 2722 2225 4514 2226 2466 2243 
  3378.       6242 2245 5218 2246 3170 2249 4706 2250 2658 2257 4450 2258 2402 2273 4322 
  3379.       2311 7186 2315 6674 2317 5650 2318 3602 2323 6418 2325 5394 2326 3346 2329 
  3380.       4882 2330 2834 2339 6290 2341 5266 2342 3218 2345 4754 2346 2706 2353 4498 
  3381.       2354 2450 2371 6226 2373 5202 2374 3154 2377 4690 2378 2642 2385 4434 2401 
  3382.       4306 2435 6194 2437 5170 2438 3122 2441 4658 2442 2610 2449 4402 2465 4274 
  3383.       2497 4210 2567 7178 2571 6666 2573 5642 2574 3594 2579 6410 2581 5386 2582 
  3384.       3338 2585 4874 2586 2826 2595 6282 2597 5258 2598 3210 2601 4746 2602 2698 
  3385.       2609 4490 2627 6218 2629 5194 2630 3146 2633 4682 2641 4426 2657 4298 2691 
  3386.       6186 2693 5162 2694 3114 2697 4650 2705 4394 2721 4266 2753 4202 2819 6170 
  3387.       2821 5146 2822 3098 2825 4634 2833 4378 2849 4250 2881 4186 2945 4154 3079 
  3388.       7174 3083 6662 3085 5638 3086 3590 3091 6406 3093 5382 3094 3334 3097 4870 
  3389.       3107 6278 3109 5254 3110 3206 3113 4742 3121 4486 3139 6214 3141 5190 3145 
  3390.       4678 3153 4422 3169 4294 3203 6182 3205 5158 3209 4646 3217 4390 3233 4262 
  3391.       3265 4198 3331 6166 3333 5142 3337 4630 3345 4374 3361 4246 3393 4182 3457 
  3392.       4150 3587 6158 3589 5134 3593 4622 3601 4366 3617 4238 3649 4174 3713 4142 
  3393.       3841 4126 4111 7681 4119 7425 4123 6913 4125 5889 4135 7297 4139 6785 4141 
  3394.       5761 4147 6529 4149 5505 4153 4993 4167 7233 4171 6721 4173 5697 4179 6465 
  3395.       4181 5441 4185 4929 4195 6337 4197 5313 4201 4801 4209 4545 4231 7201 4235 
  3396.       6689 4237 5665 4243 6433 4245 5409 4249 4897 4259 6305 4261 5281 4265 4769 
  3397.       4273 4513 4291 6241 4293 5217 4297 4705 4305 4449 4359 7185 4363 6673 4365 
  3398.       5649 4371 6417 4373 5393 4377 4881 4387 6289 4389 5265 4393 4753 4401 4497 
  3399.       4419 6225 4421 5201 4425 4689 4483 6193 4485 5169 4489 4657 4615 7177 4619 
  3400.       6665 4621 5641 4627 6409 4629 5385 4633 4873 4643 6281 4645 5257 4649 4745 
  3401.       4675 6217 4677 5193 4739 6185 4741 5161 4867 6169 4869 5145 5127 7173 5131 
  3402.       6661 5133 5637 5139 6405 5141 5381 5155 6277 5157 5253 5187 6213 5251 6181 
  3403.       5379 6165 5635 6157 6151 7171 6155 6659 6163 6403 6179 6275 6211 5189 4681 
  3404.       4433 4321 3142 2634 2386 2274 1612 1364 1252  856  744  496 
  3405.     ] def
  3406.  
  3407.     /tab213 [
  3408.          3 6144    5 5120    6 3072    9 4608   10 2560   12 1536   17 4352   18 
  3409.       2304   20 1280   24  768   33 4224   34 2176   36 1152   40  640   48  384 
  3410.         65 4160   66 2112   68 1088   72  576   80  320   96  192  129 4128  130 
  3411.       2080  132 1056  136  544  144  288  257 4112  258 2064  260 1040  264  528 
  3412.        513 4104  514 2056  516 1032 1025 4100 1026 2052 2049 4098 4097 2050 1028 
  3413.        520  272  160
  3414.     ] def
  3415.  
  3416.     /chars 10 array def
  3417.     0 1 9 {
  3418.         /i exch def
  3419.         codewords i get dup 1286 le {
  3420.             tab513 exch get 
  3421.         } {
  3422.             tab213 exch 1287 sub get
  3423.         } ifelse
  3424.         chars i 3 -1 roll put
  3425.     } for
  3426.  
  3427.     9 -1 0 {
  3428.         /i exch def
  3429.         2 i exp cvi fcs and 0 ne {
  3430.             chars i chars i get 8191 xor put
  3431.         } if
  3432.     } for
  3433.  
  3434.     % Conversion from characters to the OneCode encoding
  3435.     /barmap [
  3436.         7 2 4 3    1 10 0 0   9 12 2 8   5 5 6 11   8 9 3 1
  3437.         0 1 5 12   2 5 1 8    4 4 9 11   6 3 8 10   3 9 7 6
  3438.         5 11 1 4   8 5 2 12   9 10 0 2   7 1 6 7    3 6 4 9
  3439.         0 3 8 6    6 4 2 7    1 1 9 9    7 10 5 2   4 0 3 8
  3440.         6 2 0 4    8 11 1 0   9 8 3 12   2 6 7 7    5 1 4 10
  3441.         1 12 6 9   7 3 8 0    5 8 9 7    4 6 2 10   3 4 0 5
  3442.         8 4 5 7    7 11 1 9   6 0 9 6    0 6 4 8    2 1 3 2
  3443.         5 9 8 12   4 11 6 1   9 5 7 4    3 3 1 2    0 7 2 0
  3444.         1 3 4 1    6 10 3 5   8 7 9 4    2 11 5 6   0 8 7 12
  3445.         4 2 8 1    5 10 3 0   9 3 0 9    6 5 2 4    7 8 1 7
  3446.         5 0 4 5    2 3 0 10   6 12 9 2   3 11 1 6   8 8 7 9
  3447.         5 4 0 11   1 5 2 2    9 1 4 12   8 3 6 6    7 0 3 7
  3448.         4 7 7 5    0 12 1 11  2 9 9 0    6 8 5 3    3 10 8 2
  3449.     ] def
  3450.  
  3451.     /bbs 65 array def    
  3452.     /bhs 65 array def
  3453.     0 1 64 {
  3454.         /i exch def
  3455.         /dec chars barmap i 4 mul get get 2 barmap i 4 mul 1 add get exp cvi and 0 ne def
  3456.         /asc chars barmap i 4 mul 2 add get get 2 barmap i 4 mul 3 add get exp cvi and 0 ne def
  3457.         dec not asc not and {
  3458.             bbs i 3 height mul 8 div put
  3459.             bhs i 2 height mul 8 div put
  3460.         } if
  3461.         dec not asc and {
  3462.             bbs i 3 height mul 8 div put
  3463.             bhs i 5 height mul 8 div put        
  3464.         } if
  3465.         dec asc not and {
  3466.             bbs i 0 height mul 8 div put
  3467.             bhs i 5 height mul 8 div put        
  3468.         } if
  3469.         dec asc and {
  3470.             bbs i 0 height mul 8 div put
  3471.             bhs i 8 height mul 8 div put        
  3472.         } if
  3473.     } for
  3474.     
  3475.     % Return the arguments
  3476.     <<
  3477.     /ren (renlinear)
  3478.     /bbs bbs
  3479.     /bhs bhs
  3480.     /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
  3481.     /txt txt
  3482.     /textxalign (center)
  3483.     /opt options
  3484.     >>
  3485.  
  3486.     dontdraw not {//renlinear exec} if
  3487.  
  3488.     end
  3489.  
  3490. } bind def
  3491. % --END ENCODER onecode--
  3492.  
  3493. % --BEGIN ENCODER postnet--
  3494. % --DESC: United States Postal Service Postnet
  3495. % --EXAM: 012345
  3496. % --EXOP: includetext includecheckintext
  3497. % --RNDR: renlinear
  3498. /postnet {
  3499.  
  3500.     1 dict begin
  3501.  
  3502.     /options exch def              % We are given an option string
  3503.     /barcode exch def              % We are given a barcode string
  3504.  
  3505.     /dontdraw false def
  3506.     /includetext false def          % Enable/disable text
  3507.     /includecheckintext false def
  3508.     /textfont /Courier def
  3509.     /textsize 10 def
  3510.     /textyoffset -7 def
  3511.     /height 0.125 def
  3512.     
  3513.     % Parse the input options
  3514.     options type /stringtype eq {
  3515.         1 dict begin
  3516.         options {
  3517.             token false eq {exit} if dup length string cvs (=) search
  3518.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  3519.         } loop
  3520.         currentdict end /options exch def
  3521.     } if
  3522.     options {def} forall
  3523.  
  3524.     /textfont textfont cvlit def
  3525.     /textsize textsize cvr def
  3526.     /textyoffset textyoffset cvr def
  3527.     /height height cvr def
  3528.     
  3529.     /barlen barcode length def
  3530.  
  3531.     % Create an array containing the character mappings
  3532.     /encs
  3533.     [ (55222) (22255) (22525) (22552) (25225)
  3534.       (25252) (25522) (52225) (52252) (52522)
  3535.       (5) (5)
  3536.     ] def
  3537.  
  3538.     % Create a string of the available characters
  3539.     /barchars (0123456789) def
  3540.  
  3541.     /bhs barlen 5 mul 7 add array def
  3542.     /txt barlen 1 add array def
  3543.  
  3544.     % Put start character
  3545.     /enc encs 10 get def
  3546.     /heights enc length array def
  3547.     0 1 enc length 1 sub {
  3548.         /j exch def
  3549.         heights j enc j 1 getinterval cvi height mul 5 div put
  3550.     } for
  3551.     bhs 0 heights putinterval   % Put encoded digit into sbs
  3552.  
  3553.     /checksum 0 def
  3554.     0 1 barlen 1 sub {
  3555.         /i exch def
  3556.         % Lookup the encoding for the each barcode character
  3557.         barcode i 1 getinterval barchars exch search
  3558.         pop                                 % Discard true leaving pre
  3559.         length /indx exch def               % indx is the length of pre
  3560.         pop pop                             % Discard seek and post
  3561.         /enc encs indx get def              % Get the indxth encoding
  3562.         /heights enc length array def
  3563.         0 1 enc length 1 sub {
  3564.             /j exch def
  3565.             heights j enc j 1 getinterval cvi height mul 5 div put
  3566.         } for
  3567.         bhs i 5 mul 1 add heights putinterval   % Put encoded digit into sbs
  3568.         txt i [barcode i 1 getinterval i 5 mul 1 add 3.312 mul textyoffset textfont textsize] put
  3569.         /checksum checksum indx add def     % checksum+=indx
  3570.     } for
  3571.  
  3572.     % Put the checksum character
  3573.     /checksum 10 checksum 10 mod sub 10 mod def
  3574.     /enc encs checksum get def
  3575.     /heights enc length array def
  3576.     0 1 enc length 1 sub {
  3577.         /j exch def
  3578.         heights j enc j 1 getinterval cvi height mul 5 div put
  3579.     } for
  3580.     bhs barlen 5 mul 1 add heights putinterval  
  3581.     
  3582.     includecheckintext {
  3583.         txt barlen [barchars checksum 1 getinterval barlen 5 mul 1 add 3.312 mul textyoffset textfont textsize] put
  3584.     } {
  3585.         txt barlen [( ) barlen 5 mul 1 add 72 mul 25 div textyoffset textfont textsize] put
  3586.     } ifelse
  3587.     
  3588.     % Put end character
  3589.     /enc encs 11 get def
  3590.     /heights enc length array def
  3591.     0 1 enc length 1 sub {
  3592.         /j exch def
  3593.         heights j enc j 1 getinterval cvi height mul 5 div put
  3594.     } for
  3595.     bhs barlen 5 mul 6 add heights putinterval  
  3596.  
  3597.     % Return the arguments
  3598.     <<
  3599.     /ren (renlinear)
  3600.     /bhs bhs
  3601.     /bbs [bhs length {0} repeat]
  3602.     /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
  3603.     includetext {
  3604.         /txt txt
  3605.     } if
  3606.     /opt options
  3607.     >>
  3608.  
  3609.     dontdraw not {//renlinear exec} if
  3610.  
  3611.     end
  3612.  
  3613. } bind def
  3614. % --END ENCODER postnet--
  3615.  
  3616. % --BEGIN ENCODER royalmail--
  3617. % --DESC: Royal Mail 4 State Customer Code (RM4SCC)
  3618. % --EXAM: LE28HS9Z
  3619. % --EXOP: includetext includecheckintext barcolor=FF0000
  3620. % --RNDR: renlinear
  3621. /royalmail {
  3622.  
  3623.     1 dict begin
  3624.  
  3625.     /options exch def              % We are given an option string
  3626.     /barcode exch def              % We are given a barcode string
  3627.  
  3628.     /dontdraw false def
  3629.     /includetext false def          % Enable/disable text
  3630.     /includecheckintext false def
  3631.     /textfont /Courier def
  3632.     /textsize 10 def
  3633.     /textyoffset -7 def
  3634.     /height 0.175 def
  3635.     
  3636.     % Parse the input options
  3637.     options type /stringtype eq {
  3638.         1 dict begin
  3639.         options {
  3640.             token false eq {exit} if dup length string cvs (=) search
  3641.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  3642.         } loop
  3643.         currentdict end /options exch def
  3644.     } if
  3645.     options {def} forall
  3646.  
  3647.     /textfont textfont cvlit def
  3648.     /textsize textsize cvr def
  3649.     /textyoffset textyoffset cvr def
  3650.     /height height cvr def
  3651.     
  3652.     % Create an array containing the character mappings
  3653.     /encs
  3654.     [ (3300) (2211) (2301) (2310) (3201) (3210) 
  3655.       (1122) (0033) (0123) (0132) (1023) (1032) 
  3656.       (1302) (0213) (0303) (0312) (1203) (1212) 
  3657.       (1320) (0231) (0321) (0330) (1221) (1230) 
  3658.       (3102) (2013) (2103) (2112) (3003) (3012) 
  3659.       (3120) (2031) (2121) (2130) (3021) (3030) 
  3660.       (2) (3)
  3661.     ] def
  3662.  
  3663.     % Create a string of the available characters
  3664.     /barchars (ZUVWXY501234B6789AHCDEFGNIJKLMTOPQRS) def
  3665.  
  3666.     /barlen barcode length def
  3667.     /encstr barlen 4 mul 6 add string def
  3668.     /txt barlen 1 add array def
  3669.  
  3670.     % Put start character
  3671.     encstr 0 encs 36 get putinterval
  3672.     
  3673.     /checksumrow 0 def
  3674.     /checksumcol 0 def
  3675.     0 1 barlen 1 sub {
  3676.         /i exch def
  3677.         % Lookup the encoding for the each barcode character
  3678.         barcode i 1 getinterval barchars exch search
  3679.         pop                                 % Discard true leaving pre
  3680.         length /indx exch def               % indx is the length of pre
  3681.         pop pop                             % Discard seek and post
  3682.         /enc encs indx get def              % Get the indxth encoding
  3683.         encstr i 4 mul 1 add enc putinterval
  3684.         txt i [barcode i 1 getinterval i 4 mul 1 add 3.312 mul textyoffset textfont textsize] put
  3685.         /checksumrow checksumrow indx 6 idiv add def
  3686.         /checksumcol checksumcol indx 6 mod add def 
  3687.     } for
  3688.  
  3689.     % Put the checksum character
  3690.     /checksum checksumrow 6 mod 6 mul checksumcol 6 mod add def
  3691.     /enc encs checksum get def
  3692.     encstr barlen 4 mul 1 add enc putinterval
  3693.     includecheckintext {
  3694.         txt barlen [barchars checksum 1 getinterval barlen 4 mul 1 add 3.312 mul textyoffset textfont textsize] put
  3695.     } {
  3696.         txt barlen [( ) barlen 4 mul 1 add 3.312 mul textyoffset textfont textsize] put
  3697.     } ifelse
  3698.     
  3699.     % Put end character
  3700.     encstr barlen 4 mul 5 add encs 37 get putinterval  
  3701.  
  3702.     /bbs encstr length array def    
  3703.     /bhs encstr length array def
  3704.     0 1 encstr length 1 sub {
  3705.         /i exch def
  3706.         /enc encstr i 1 getinterval def
  3707.         enc (0) eq {
  3708.             bbs i 3 height mul 8 div put
  3709.             bhs i 2 height mul 8 div put
  3710.         } if
  3711.         enc (1) eq {
  3712.             bbs i 0 height mul 8 div put
  3713.             bhs i 5 height mul 8 div put
  3714.         } if
  3715.         enc (2) eq {
  3716.             bbs i 3 height mul 8 div put
  3717.             bhs i 5 height mul 8 div put
  3718.         } if
  3719.         enc (3) eq {
  3720.             bbs i 0 height mul 8 div put
  3721.             bhs i 8 height mul 8 div put
  3722.         } if
  3723.     } for
  3724.     
  3725.     % Return the arguments
  3726.     <<
  3727.     /ren (renlinear)
  3728.     /bbs bbs
  3729.     /bhs bhs
  3730.     /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
  3731.     includetext {
  3732.         /txt txt
  3733.     } if
  3734.     /opt options
  3735.     >>
  3736.  
  3737.     dontdraw not {//renlinear exec} if
  3738.  
  3739.     end
  3740.  
  3741. } bind def
  3742. % --END ENCODER royalmail--
  3743.  
  3744. % --BEGIN ENCODER auspost--
  3745. % --DESC: AusPost 4 State Customer Code
  3746. % --EXAM: 5956439111ABA 9
  3747. % --EXOP: includetext custinfoenc=character
  3748. % --RNDR: renlinear
  3749. /auspost {
  3750.  
  3751.     1 dict begin
  3752.  
  3753.     /options exch def              % We are given an option string
  3754.     /barcode exch def              % We are given a barcode string
  3755.  
  3756.     /dontdraw false def
  3757.     /includetext false def         % Enable/disable text
  3758.     /textfont /Courier def
  3759.     /textsize 10 def
  3760.     /textyoffset -7 def
  3761.     /height 0.175 def
  3762.     /custinfoenc (character) def
  3763.     
  3764.     % Parse the input options
  3765.     options type /stringtype eq {
  3766.         1 dict begin
  3767.         options {
  3768.             token false eq {exit} if dup length string cvs (=) search
  3769.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  3770.         } loop
  3771.         currentdict end /options exch def
  3772.     } if
  3773.     options {def} forall
  3774.  
  3775.     /textfont textfont cvlit def
  3776.     /textsize textsize cvr def
  3777.     /textyoffset textyoffset cvr def
  3778.     /height height cvr def
  3779.  
  3780.     % Create an array containing the character mappings
  3781.     /encs
  3782.     [ (000) (001) (002) (010) (011) (012) (020) (021)
  3783.       (022) (100) (101) (102) (110) (111) (112) (120)
  3784.       (121) (122) (200) (201) (202) (210) (211) (212)
  3785.       (220) (221) (222) (300) (301) (302) (310) (311)
  3786.       (312) (320) (321) (322) (023) (030) (031) (032)
  3787.       (033) (103) (113) (123) (130) (131) (132) (133)
  3788.       (203) (213) (223) (230) (231) (232) (233) (303)
  3789.       (313) (323) (330) (331) (332) (333) (003) (013)
  3790.       (00) (01) (02) (10) (11) (12) (20) (21) (22) (30)
  3791.       (13) (3)
  3792.     ] def
  3793.  
  3794.     % Create a string of the available characters
  3795.     /barchars (ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz #) def
  3796.     
  3797.     /barlen barcode length def
  3798.     barcode 0 2 getinterval (11) eq {37} if
  3799.     barcode 0 2 getinterval (45) eq {37} if
  3800.     barcode 0 2 getinterval (59) eq {52} if
  3801.     barcode 0 2 getinterval (62) eq {67} if
  3802.     /encstr exch string def
  3803.     /txt barlen 2 sub array def
  3804.  
  3805.     % Put start character
  3806.     encstr 0 encs 74 get putinterval
  3807.  
  3808.     % Encode the FCC
  3809.     0 1 1 {
  3810.         /i exch def       
  3811.         encs barcode i 1 getinterval cvi 64 add get
  3812.         encstr i 2 mul 2 add 3 2 roll putinterval
  3813.     } for
  3814.     
  3815.     % Encode the DPID
  3816.     2 1 9 {
  3817.         /i exch def       
  3818.         encs barcode i 1 getinterval cvi 64 add get
  3819.         encstr i 2 mul 2 add 3 2 roll putinterval
  3820.         txt i 2 sub [barcode i 1 getinterval i 2 sub 2 mul 6 add 3.312 mul textyoffset textfont textsize] put
  3821.     } for
  3822.     
  3823.     % Encode the customer information   
  3824.     custinfoenc (numeric) eq {
  3825.         0 1 barlen 11 sub {
  3826.             /i exch def
  3827.             encs barcode i 10 add 1 getinterval cvi 64 add get
  3828.             encstr i 2 mul 22 add 3 2 roll putinterval
  3829.             txt i 8 add [barcode i 10 add 1 getinterval i 2 mul 22 add 3.312 mul textyoffset textfont textsize] put
  3830.         } for        
  3831.         /ciflen barlen 10 sub 2 mul def
  3832.     } {
  3833.         0 1 barlen 11 sub {
  3834.             /i exch def           
  3835.             barcode i 10 add 1 getinterval barchars exch search
  3836.             pop                                
  3837.             length /indx exch def           
  3838.             pop pop                            
  3839.             /enc encs indx get def          
  3840.             encstr i 3 mul 22 add enc putinterval
  3841.             txt i 8 add [barcode i 10 add 1 getinterval i 3 mul 22 add 3.312 mul textyoffset textfont textsize] put
  3842.         } for        
  3843.         /ciflen barlen 10 sub 3 mul def
  3844.     } ifelse
  3845.  
  3846.     % Add any filler characters
  3847.     22 ciflen add 1 encstr length 14 sub {        
  3848.         encstr exch encs 75 get putinterval
  3849.     } for
  3850.     
  3851.     % Create the 64x64 Reed-Solomon table
  3852.     /rstable 64 64 mul array def
  3853.     rstable 0 [ 64 {0} repeat ] putinterval
  3854.     rstable 64 [ 0 1 63 {} for ] putinterval
  3855.     /prev 1 def
  3856.     64 {       
  3857.         /next prev 1 bitshift def
  3858.         next 64 and 0 ne {
  3859.             /next next 67 xor def
  3860.         } if        
  3861.         0 1 63 {
  3862.             /j exch def
  3863.             /nextcell {rstable 64 next mul j add} def
  3864.             nextcell rstable 64 prev mul j add get 1 bitshift put
  3865.             nextcell get 64 and 0 ne {
  3866.                 nextcell nextcell get 67 xor put
  3867.             } if
  3868.         } for
  3869.         /prev next def
  3870.     } repeat
  3871.     
  3872.     % Calculate the Reed-Solomon codes for triples
  3873.     /rscodes encstr length 16 sub 3 idiv 4 add array def
  3874.     rscodes 0 [ 4 {0} repeat ] putinterval
  3875.     2 3 encstr length 16 sub {
  3876.         /i exch def
  3877.         rscodes rscodes length i 2 sub 3 idiv sub 1 sub
  3878.         encstr i 1 getinterval cvi 16 mul
  3879.         encstr i 1 add 1 getinterval cvi 4 mul add
  3880.         encstr i 2 add 1 getinterval cvi add        
  3881.         put
  3882.     } for    
  3883.     rscodes length 5 sub -1 0 {
  3884.        /i exch def
  3885.        0 1 4 {
  3886.            /j exch def
  3887.            rscodes i j add rscodes i j add get
  3888.            rstable 64 [48 17 29 30 1] j get mul rscodes i 4 add get add get
  3889.            xor put
  3890.        } for
  3891.     } for
  3892.     /checkcode (000000000000) 12 string copy def
  3893.     0 1 3 {
  3894.         /i exch def
  3895.         /enc rscodes 3 i sub get 4 3 string cvrs def
  3896.         checkcode i 3 mul 3 enc length sub add enc putinterval
  3897.     } for
  3898.     
  3899.     % Put checkcode and end characters
  3900.     encstr encstr length 14 sub checkcode putinterval
  3901.     encstr encstr length 2 sub encs 74 get putinterval 
  3902.  
  3903.     /bbs encstr length array def    
  3904.     /bhs encstr length array def
  3905.     0 1 encstr length 1 sub {
  3906.         /i exch def
  3907.         /enc encstr i 1 getinterval def
  3908.         enc (0) eq {
  3909.             bbs i 0 height mul 8 div put
  3910.             bhs i 8 height mul 8 div put
  3911.         } if
  3912.         enc (1) eq {
  3913.             bbs i 3 height mul 8 div put
  3914.             bhs i 5 height mul 8 div put
  3915.         } if
  3916.         enc (2) eq {
  3917.             bbs i 0 height mul 8 div put
  3918.             bhs i 5 height mul 8 div put
  3919.         } if
  3920.         enc (3) eq {
  3921.             bbs i 3 height mul 8 div put
  3922.             bhs i 2 height mul 8 div put
  3923.         } if
  3924.     } for   
  3925.     
  3926.     % Return the arguments
  3927.     <<
  3928.     /ren (renlinear)
  3929.     /bbs bbs
  3930.     /bhs bhs
  3931.     /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
  3932.     includetext {
  3933.         /txt txt
  3934.     } if
  3935.     /opt options
  3936.     >>
  3937.  
  3938.     dontdraw not {//renlinear exec} if
  3939.  
  3940.     end
  3941.  
  3942. } bind def
  3943. % --END ENCODER auspost--
  3944.  
  3945. % --BEGIN ENCODER kix--
  3946. % --DESC: Royal Dutch TPG Post KIX 4-State Barcode
  3947. % --EXAM: 1231FZ13XHS
  3948. % --EXOP: includetext includecheckintext
  3949. % --RNDR: renlinear
  3950. /kix {
  3951.  
  3952.     1 dict begin
  3953.  
  3954.     /options exch def              % We are given an option string
  3955.     /barcode exch def              % We are given a barcode string
  3956.  
  3957.     /dontdraw false def
  3958.     /includetext false def          % Enable/disable text
  3959.     /includecheckintext false def
  3960.     /textfont /Courier def
  3961.     /textsize 10 def
  3962.     /textyoffset -7 def
  3963.     /height 0.175 def
  3964.     
  3965.     % Parse the input options
  3966.     options type /stringtype eq {
  3967.         1 dict begin
  3968.         options {
  3969.             token false eq {exit} if dup length string cvs (=) search
  3970.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  3971.         } loop
  3972.         currentdict end /options exch def
  3973.     } if
  3974.     options {def} forall
  3975.  
  3976.     /textfont textfont cvlit def
  3977.     /textsize textsize cvr def
  3978.     /textyoffset textyoffset cvr def
  3979.     /height height cvr def
  3980.     
  3981.     % Create an array containing the character mappings
  3982.     /encs
  3983.     [ (0033) (0123) (0132) (1023) (1032) (1122)
  3984.       (0213) (0303) (0312) (1203) (1212) (1302) 
  3985.       (0231) (0321) (0330) (1221) (1230) (1320)
  3986.       (2013) (2103) (2112) (3003) (3012) (3102)
  3987.       (2031) (2121) (2130) (3021) (3030) (3120) 
  3988.       (2211) (2301) (2310) (3201) (3210) (3300) 
  3989.     ] def
  3990.  
  3991.     % Create a string of the available characters
  3992.     /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ) def
  3993.  
  3994.     /barlen barcode length def
  3995.     /encstr barlen 4 mul string def
  3996.     /txt barlen array def
  3997.     
  3998.     0 1 barlen 1 sub {
  3999.         /i exch def
  4000.         % Lookup the encoding for the each barcode character
  4001.         barcode i 1 getinterval barchars exch search
  4002.         pop                                 % Discard true leaving pre
  4003.         length /indx exch def               % indx is the length of pre
  4004.         pop pop                             % Discard seek and post
  4005.         /enc encs indx get def              % Get the indxth encoding
  4006.         encstr i 4 mul enc putinterval
  4007.         txt i [barcode i 1 getinterval i 4 mul 3.312 mul textyoffset textfont textsize] put
  4008.     } for
  4009.  
  4010.     /bbs encstr length array def    
  4011.     /bhs encstr length array def
  4012.     0 1 encstr length 1 sub {
  4013.         /i exch def
  4014.         /enc encstr i 1 getinterval def
  4015.         enc (0) eq {
  4016.             bbs i 3 height mul 8 div put
  4017.             bhs i 2 height mul 8 div put
  4018.         } if
  4019.         enc (1) eq {
  4020.             bbs i 0 height mul 8 div put
  4021.             bhs i 5 height mul 8 div put
  4022.         } if
  4023.         enc (2) eq {
  4024.             bbs i 3 height mul 8 div put
  4025.             bhs i 5 height mul 8 div put
  4026.         } if
  4027.         enc (3) eq {
  4028.             bbs i 0 height mul 8 div put
  4029.             bhs i 8 height mul 8 div put
  4030.         } if
  4031.     } for
  4032.     
  4033.     % Return the arguments
  4034.     <<
  4035.     /ren (renlinear)
  4036.     /bbs bbs
  4037.     /bhs bhs
  4038.     /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
  4039.     includetext {
  4040.         /txt txt
  4041.     } if
  4042.     /opt options
  4043.     >>
  4044.  
  4045.     dontdraw not {//renlinear exec} if
  4046.  
  4047.     end
  4048.  
  4049. } bind def
  4050. % --END ENCODER kix--
  4051.  
  4052. % --BEGIN ENCODER japanpost--
  4053. % --DESC: Japan Post 4 State Customer Code
  4054. % --EXAM: 6540123789-A-K-Z
  4055. % --EXOP: includetext includecheckintext
  4056. % --RNDR: renlinear
  4057. /japanpost {
  4058.  
  4059.     1 dict begin
  4060.  
  4061.     /options exch def              % We are given an option string
  4062.     /barcode exch def              % We are given a barcode string
  4063.  
  4064.     /dontdraw false def
  4065.     /includetext false def          % Enable/disable text
  4066.     /includecheckintext false def
  4067.     /textfont /Courier def
  4068.     /textsize 10 def
  4069.     /textyoffset -7 def
  4070.     /height 0.175 def
  4071.   
  4072.     % Parse the input options
  4073.     options type /stringtype eq {
  4074.         1 dict begin
  4075.         options {
  4076.             token false eq {exit} if dup length string cvs (=) search
  4077.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  4078.         } loop
  4079.         currentdict end /options exch def
  4080.     } if
  4081.     options {def} forall
  4082.  
  4083.     /textfont textfont cvlit def
  4084.     /textsize textsize cvr def
  4085.     /textyoffset textyoffset cvr def
  4086.     /height height cvr def
  4087.     
  4088.     % Create an array containing the character mappings
  4089.     % 0123456789- C1C2C3C4C5C6C7C8 ST EN
  4090.     /encs
  4091.     [ (300) (330) (312) (132) (321) (303) (123) (231) (213) (033) (030)
  4092.       (120) (102) (210) (012) (201) (021) (003) (333) 
  4093.       (31) (13)
  4094.     ] def
  4095.  
  4096.     % Create a string of the available characters
  4097.     /barchars (0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ) def
  4098.     /barlen barcode length def
  4099.     
  4100.     /encstr 20 1 add 3 mul 4 add string def
  4101.     /digits 20 array def
  4102.     /txt barlen 1 add array def
  4103.  
  4104.     % Put start character
  4105.     encstr 0 encs 19 get putinterval
  4106.  
  4107.     /checksum 0 def
  4108.     /j 0 def /i 0 def
  4109.     0 1 barlen 1 sub {
  4110.         /i exch def
  4111.         barcode i 1 getinterval barchars exch search
  4112.         pop                                  % Discard true leaving pre
  4113.         length /indx exch def                % indx is the length of pre
  4114.         pop pop                              % Discard match and post
  4115.         indx 11 ge indx 37 lt and {          % Insert escape
  4116.             j 18 gt {exit} if                % Should fit in 20 chars
  4117.                                              % 11-20: C1 (11)
  4118.                                              % 21-30: C2 (12)
  4119.                                              % 31-36: C3 (13)
  4120.             /digit indx 1 sub 10 idiv 10 add def
  4121.             encstr j 3 mul 2 add encs digit get putinterval
  4122.             /checksum checksum digit add def
  4123.             digits j digit put
  4124.             /j j 1 add def
  4125.         } if
  4126.         j 19 gt {exit} if                    % Should fit in 20 chars
  4127.         /digit 0 def
  4128.         indx 37 eq {
  4129.             /digit 14 def                    % space (C14)
  4130.         } if
  4131.         indx 11 ge indx 37 lt and {
  4132.             /digit indx 1 sub 10 mod def
  4133.         } if
  4134.         indx 11 lt {
  4135.             /digit indx def
  4136.         } if
  4137.         encstr j 3 mul 2 add encs digit get putinterval % space
  4138.         /checksum checksum digit add def
  4139.         digits j digit put
  4140.         txt i [barcode i 1 getinterval j 3 mul 2 add 3.312 mul textyoffset textfont textsize] put
  4141.         /j j 1 add def
  4142.     } for
  4143.  
  4144.     % Fill spaces (c14) at right end
  4145.     j 1 20 1 sub {
  4146.         /k exch def
  4147.         encstr k 3 mul 2 add encs 14 get putinterval
  4148.         /checksum checksum 14 add def
  4149.         digits k 14 put
  4150.     } for
  4151.  
  4152.     % Put the checksum character
  4153.     /checksum checksum 19 mod 19 exch sub def
  4154.     encstr 2 20 3 mul add encs checksum get putinterval
  4155.  
  4156.     % Put end character
  4157.     encstr 2 21 3 mul add encs 20 get putinterval
  4158.     /checkdigit ( ) def
  4159.     includecheckintext {
  4160.         /checkdigit barchars checksum 1 getinterval def
  4161.     } if
  4162.     txt i 1 add [ checkdigit 20 3 mul 2 add 3.312 mul textyoffset textfont textsize] put
  4163.  
  4164.     % Put end character
  4165.     encstr 20 1 add 3 mul 2 add encs 20 get putinterval
  4166.  
  4167.     /bbs 21 3 mul 4 add array def
  4168.     /bhs bbs length array def
  4169.     0 1 bbs length 1 sub {
  4170.         /i exch def
  4171.         /enc encstr i 1 getinterval def
  4172.         /bunit 0 def
  4173.         /hunit 0 def
  4174.         enc (0) eq {
  4175.             /bunit 3 def
  4176.             /hunit 2 def
  4177.         } if
  4178.         enc (1) eq {
  4179.             /bunit 0 def
  4180.             /hunit 5 def
  4181.         } if
  4182.         enc (2) eq {
  4183.             /bunit 3 def
  4184.             /hunit 5 def
  4185.         } if
  4186.         enc (3) eq {
  4187.             /bunit 0 def
  4188.             /hunit 8 def
  4189.         } if
  4190.         bbs i bunit height mul 8 div put
  4191.         bhs i hunit height mul 8 div put
  4192.     } for
  4193.  
  4194.     % Return the arguments
  4195.     <<
  4196.     /ren (renlinear)
  4197.     /bbs bbs
  4198.     /bhs bhs
  4199.     /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
  4200.     includetext {
  4201.         /txt txt
  4202.     } if
  4203.     /opt options
  4204.     >>
  4205.  
  4206.     dontdraw not {//renlinear exec} if
  4207.  
  4208.     end
  4209.  
  4210. } bind def
  4211. % --END ENCODER japanpost--
  4212.  
  4213. % --BEGIN ENCODER msi--
  4214. % --DESC: MSI Modified Plessey
  4215. % --EXAM: 0123456789
  4216. % --EXOP: includetext includecheck includecheckintext
  4217. % --RNDR: renlinear
  4218. /msi {
  4219.  
  4220.     1 dict begin                 % Confine variables to local scope
  4221.  
  4222.     /options exch def       % We are given an option string
  4223.     /barcode exch def       % We are given a barcode string
  4224.  
  4225.     /dontdraw false def
  4226.     /includecheck false def  % Enable/disable checkdigit
  4227.     /includetext false def   % Enable/disable text
  4228.     /includecheckintext false def
  4229.     /textfont /Courier def
  4230.     /textsize 10 def
  4231.     /textyoffset -7 def
  4232.     /height 1 def
  4233.     
  4234.     % Parse the input options
  4235.     options type /stringtype eq {
  4236.         1 dict begin
  4237.         options {
  4238.             token false eq {exit} if dup length string cvs (=) search
  4239.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  4240.         } loop
  4241.         currentdict end /options exch def
  4242.     } if
  4243.     options {def} forall
  4244.     
  4245.     /textfont textfont cvlit def
  4246.     /textsize textsize cvr def
  4247.     /textyoffset textyoffset cvr def
  4248.     /height height cvr def
  4249.     
  4250.     % Create an array containing the character mappings
  4251.     /encs
  4252.     [ (13131313) (13131331) (13133113) (13133131) (13311313)
  4253.       (13311331) (13313113) (13313131) (31131313) (31131331)
  4254.       (31) (131)
  4255.     ] def
  4256.  
  4257.     % Create a string of the available characters
  4258.     /barchars (0123456789) def
  4259.  
  4260.     /barlen barcode length def     % Length of the code
  4261.  
  4262.     includecheck {
  4263.         /sbs barlen 8 mul 13 add string def
  4264.         /txt barlen 1 add array def
  4265.     } {
  4266.         /sbs barlen 8 mul 5 add string def
  4267.         /txt barlen array def
  4268.     } ifelse
  4269.  
  4270.     % Put start character
  4271.     sbs 0 encs 10 get putinterval
  4272.     /checksum 0 def
  4273.  
  4274.     0 1 barlen 1 sub {
  4275.         /i exch def
  4276.         % Lookup the encoding for the each barcode character
  4277.         barcode i 1 getinterval barchars exch search
  4278.         pop                                % Discard true leaving pre
  4279.         length /indx exch def              % indx is the length of pre
  4280.         pop pop                            % Discard seek and post
  4281.         /enc encs indx get def             % Get the indxth encoding
  4282.         sbs i 8 mul 2 add enc putinterval  % Put encoded digit into sbs
  4283.         txt i [barcode i 1 getinterval i 16 mul 4 add textyoffset textfont textsize] put
  4284.         barlen i sub 2 mod 0 eq {
  4285.             /checksum indx checksum add def
  4286.         } {
  4287.             /checksum indx 2 mul dup 10 idiv add checksum add def
  4288.         } ifelse
  4289.     } for
  4290.  
  4291.     % Put the checksum and end characters
  4292.     includecheck {
  4293.         /checksum 10 checksum 10 mod sub 10 mod def
  4294.         sbs barlen 8 mul 2 add encs checksum get putinterval
  4295.         includecheckintext {
  4296.             txt barlen [barchars checksum 1 getinterval barlen 16 mul 4 add textyoffset textfont textsize] put
  4297.         } {
  4298.             txt barlen [( ) barlen 16 mul 4 add textyoffset textfont textsize] put
  4299.         } ifelse
  4300.         sbs barlen 8 mul 10 add encs 11 get putinterval
  4301.     } {
  4302.         sbs barlen 8 mul 2 add encs 11 get putinterval
  4303.     } ifelse
  4304.  
  4305.     % Return the arguments
  4306.     <<
  4307.     /ren (renlinear)
  4308.     /sbs [sbs {48 sub} forall]
  4309.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  4310.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  4311.     includetext {
  4312.         /txt txt
  4313.     } if
  4314.     /opt options
  4315.     >>
  4316.  
  4317.     dontdraw not {//renlinear exec} if
  4318.  
  4319.     end
  4320.  
  4321. } bind def
  4322. % --END ENCODER msi--
  4323.  
  4324. % --BEGIN ENCODER plessey--
  4325. % --DESC: Plessey
  4326. % --EXAM: 01234ABCD
  4327. % --EXOP: includetext includecheckintext
  4328. % --RNDR: renlinear
  4329. /plessey {
  4330.  
  4331.     1 dict begin                  % Confine variables to local scope
  4332.  
  4333.     /options exch def        % We are given an option string
  4334.     /barcode exch def        % We are given a barcode string
  4335.  
  4336.     /dontdraw false def
  4337.     /includetext false def    % Enable/disable text
  4338.     /includecheckintext false def
  4339.     /textfont /Courier def
  4340.     /textsize 10 def
  4341.     /textyoffset -7 def
  4342.     /height 1 def
  4343.     
  4344.     % Parse the input options
  4345.     options type /stringtype eq {
  4346.         1 dict begin
  4347.         options {
  4348.             token false eq {exit} if dup length string cvs (=) search
  4349.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  4350.         } loop
  4351.         currentdict end /options exch def
  4352.     } if
  4353.     options {def} forall
  4354.  
  4355.     /textfont textfont cvlit def
  4356.     /textsize textsize cvr def
  4357.     /textyoffset textyoffset cvr def
  4358.     /height height cvr def
  4359.     
  4360.     % Create an array containing the character mappings
  4361.     /encs
  4362.     [ (13131313) (31131313) (13311313) (31311313)
  4363.       (13133113) (31133113) (13313113) (31313113)
  4364.       (13131331) (31131331) (13311331) (31311331)
  4365.       (13133131) (31133131) (13313131) (31313131)
  4366.       (31311331) (331311313)
  4367.     ] def
  4368.  
  4369.     % Create a string of the available characters
  4370.     /barchars (0123456789ABCDEF) def
  4371.  
  4372.     /barlen barcode length def     % Length of the code
  4373.     /sbs barlen 8 mul 33 add string def
  4374.     /txt barlen 2 add array def
  4375.     /checkbits barlen 4 mul 8 add array def
  4376.     checkbits barlen 4 mul [ 0 0 0 0 0 0 0 0 ] putinterval
  4377.  
  4378.     % Put start character
  4379.     sbs 0 encs 16 get putinterval
  4380.  
  4381.     0 1 barlen 1 sub {
  4382.         /i exch def
  4383.         % Lookup the encoding for the each barcode character
  4384.         barcode i 1 getinterval barchars exch search
  4385.         pop                                % Discard true leaving pre
  4386.         length /indx exch def              % indx is the length of pre
  4387.         pop pop                            % Discard seek and post
  4388.         /enc encs indx get def             % Get the indxth encoding
  4389.         sbs i 8 mul 8 add enc putinterval  % Put encoded digit into sbs
  4390.         txt i [barcode i 1 getinterval i 16 mul 16 add textyoffset textfont textsize] put
  4391.         checkbits i 4 mul [
  4392.                 indx 1 and
  4393.                 indx -1 bitshift 1 and
  4394.                 indx -2 bitshift 1 and
  4395.                 indx -3 bitshift
  4396.         ] putinterval
  4397.     } for
  4398.  
  4399.     % Checksum is last 8 bits of a CRC using a salt
  4400.     /checksalt [ 1 1 1 1 0 1 0 0 1 ] def
  4401.     0 1 barlen 4 mul 1 sub {
  4402.         /i exch def
  4403.         checkbits i get 1 eq {
  4404.             0 1 8 {
  4405.                 /j exch def
  4406.                 checkbits i j add checkbits i j add get checksalt j get xor put
  4407.             } for
  4408.         } if
  4409.     } for
  4410.  
  4411.     % Calculate the value of the checksum digits
  4412.     /checkval 0 def
  4413.     0 1 7 {
  4414.         /i exch def
  4415.         /checkval checkval 2 7 i sub exp cvi checkbits barlen 4 mul i add get mul add def
  4416.     } for
  4417.  
  4418.     % Put the checksum characters
  4419.     /checksum1 checkval -4 bitshift def
  4420.     /checksum2 checkval 15 and def
  4421.     sbs barlen 8 mul 8 add encs checksum1 get putinterval
  4422.     sbs barlen 8 mul 16 add encs checksum2 get putinterval
  4423.     includecheckintext {
  4424.         txt barlen [barchars checksum1 1 getinterval barlen 16 mul 16 add textyoffset textfont textsize] put
  4425.         txt barlen 1 add [barchars checksum2 1 getinterval barlen 1 add 16 mul 16 add textyoffset textfont textsize] put
  4426.     } {
  4427.         txt barlen [( ) barlen 16 mul 16 add textyoffset textfont textsize] put
  4428.         txt barlen 1 add [( ) barlen 1 add 16 mul 16 add textyoffset textfont textsize] put
  4429.     } ifelse
  4430.  
  4431.     % Put end character
  4432.     sbs barlen 8 mul 24 add encs 17 get putinterval
  4433.  
  4434.     % Return the arguments
  4435.     <<
  4436.     /ren (renlinear)
  4437.     /sbs [sbs {48 sub} forall]
  4438.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  4439.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  4440.     includetext {
  4441.         /txt txt
  4442.     } if
  4443.     /opt options
  4444.     >>
  4445.  
  4446.     dontdraw not {//renlinear exec} if
  4447.  
  4448.     end
  4449.  
  4450. } bind def
  4451. % --END ENCODER plessey--
  4452.  
  4453. % --BEGIN ENCODER raw--
  4454. % --DESC: Raw bar space succession for custom symbologies 
  4455. % --EXAM: 331132131313411122131311333213114131131221323
  4456. % --EXOP: height=0.5
  4457. % --RNDR: renlinear
  4458. /raw {
  4459.  
  4460.     1 dict begin                  % Confine variables to local scope
  4461.  
  4462.     /options exch def        % We are given an option string
  4463.     /sbs exch def        % We are given a barcode string
  4464.  
  4465.     /dontdraw false def
  4466.     /height 1 def
  4467.  
  4468.     % Parse the input options
  4469.     options type /stringtype eq {
  4470.         1 dict begin
  4471.         options {
  4472.             token false eq {exit} if dup length string cvs (=) search
  4473.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  4474.         } loop
  4475.         currentdict end /options exch def
  4476.     } if
  4477.     options {def} forall
  4478.  
  4479.     /height height cvr def
  4480.  
  4481.     % Return the arguments
  4482.     <<
  4483.     /ren (renlinear)
  4484.     /sbs [sbs {48 sub} forall]
  4485.     /bhs [sbs length 1 add 2 idiv {height} repeat]
  4486.     /bbs [sbs length 1 add 2 idiv {0} repeat]
  4487.     /opt options
  4488.     >>
  4489.  
  4490.     dontdraw not {//renlinear exec} if
  4491.  
  4492.     end
  4493.  
  4494. } bind def
  4495. % --END ENCODER raw--
  4496.  
  4497. % --BEGIN ENCODER symbol--
  4498. % --DESC: Miscellaneous symbols
  4499. % --EXAM: fima
  4500. % --EXOP: backgroundcolor=DD000011
  4501. % --RNDR: renlinear
  4502. /symbol {
  4503.  
  4504.     1 dict begin            % Confine variables to local scope
  4505.  
  4506.     /options exch def  % We are given an option string
  4507.     /barcode exch def  % We are given a barcode string
  4508.  
  4509.     /dontdraw false def
  4510.  
  4511.     barcode (fima) eq {
  4512.         /sbs [2.25 2.25 2.25 11.25 2.25 11.25 2.25 2.25 2.25] def
  4513.         /bhs [.625 .625 .625 .625 .625] def
  4514.         /bbs [0 0 0 0 0] def
  4515.     } if
  4516.  
  4517.     barcode (fimb) eq {
  4518.         /sbs [2.25 6.75 2.25 2.25 2.25 6.25 2.25 2.25 2.25 6.75 2.25] def
  4519.         /bhs [.625 .625 .625 .625 .625 .625] def
  4520.         /bbs [0 0 0 0 0 0] def
  4521.     } if
  4522.  
  4523.     barcode (fimc) eq {
  4524.         /sbs [2.25 2.25 2.25 6.75 2.25 6.75 2.25 6.75 2.25 2.25 2.25] def
  4525.         /bhs [.625 .625 .625 .625 .625 .625] def
  4526.         /bbs [0 0 0 0 0 0] def
  4527.     } if
  4528.     
  4529.     barcode (fimd) eq {
  4530.         /sbs [2.25 2.25 2.25 2.25 2.25 6.75 2.25 6.75 2.25 2.25 2.25 2.25 2.25] def
  4531.         /bhs [.625 .625 .625 .625 .625 .625 .625] def
  4532.         /bbs [0 0 0 0 0 0 0] def
  4533.     } if
  4534.     
  4535.     % Return the arguments
  4536.     <<
  4537.     /ren (renlinear)
  4538.     /sbs sbs
  4539.     /bhs bhs
  4540.     /bbs bbs
  4541.     /opt options
  4542.     >>
  4543.  
  4544.     dontdraw not {//renlinear exec} if
  4545.  
  4546.     end
  4547.  
  4548. } bind def
  4549. % --END ENCODER symbol--
  4550.  
  4551. % --BEGIN ENCODER pdf417--
  4552. % --DESC: PDF417
  4553. % --EXAM: ^453^178^121^239
  4554. % --EXOP: columns=2 rows=10
  4555. % --RNDR: renmatrix
  4556. /pdf417 {
  4557.  
  4558.     1 dict begin
  4559.  
  4560.     /options exch def
  4561.     /barcode exch def
  4562.  
  4563.     /dontdraw false def
  4564.     /compact false def
  4565.     /eclevel -1 def
  4566.     /columns 0 def
  4567.     /rows 0 def
  4568.     /rowmult 3 def
  4569.  
  4570.     % Parse the input options
  4571.     options type /stringtype eq {
  4572.         1 dict begin
  4573.         options {
  4574.             token false eq {exit} if dup length string cvs (=) search
  4575.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  4576.         } loop
  4577.         currentdict end /options exch def
  4578.     } if
  4579.     options {def} forall
  4580.  
  4581.     /eclevel eclevel cvi def
  4582.     /columns columns cvi def
  4583.     /rows rows cvi def
  4584.     /rowmult rowmult cvr def
  4585.  
  4586.     % Split the input barcode into an array of codewords
  4587.     /datcws barcode length array def
  4588.     /i 0 def /j 0 def
  4589.     { % loop
  4590.         i barcode length eq {exit} if
  4591.         /cw barcode i 1 add 3 getinterval cvi def
  4592.         datcws j cw put
  4593.         /i i 4 add def
  4594.         /j j 1 add def
  4595.     } loop
  4596.     /datcws datcws 0 j getinterval def
  4597.  
  4598.     % Determine the error correction level if unspecified
  4599.     /m datcws length def
  4600.     eclevel -1 eq {
  4601.         m 40 le {/eclevel 2 def} if
  4602.         m 41 ge m 160 le and {/eclevel 3 def} if
  4603.         m 161 ge m 320 le and {/eclevel 4 def} if
  4604.         m 321 ge {/eclevel 5 def} if
  4605.     } if
  4606.  
  4607.     % Reduce the error level so that it does not cause an excessive number of codewords
  4608.     /maxeclevel 928 1 sub m sub ln 2 ln div cvi 1 sub def
  4609.     eclevel maxeclevel gt {/eclevel maxeclevel def} if
  4610.     /k 2 eclevel 1 add exp cvi def
  4611.  
  4612.     % To determine size of matrix, number of columns if given by user...
  4613.     columns 1 ge columns 30 le and {/c columns def} if
  4614.  
  4615.     % ... and rows is greater of those required and that given by user within limits
  4616.     /r m k add 1 add columns div ceiling cvi def  % Required
  4617.     r rows lt rows 90 le and {/r rows def} if
  4618.     r 3 lt {/r 3 def} if
  4619.  
  4620.     % Opportunistically raise the error level if a better fit to the matrix is possible
  4621.     /maxeclevel c r mul 1 sub m sub ln 2 ln div cvi 1 sub def
  4622.     maxeclevel eclevel gt {
  4623.       /eclevel maxeclevel def
  4624.       /k 2 eclevel 1 add exp cvi def
  4625.     } if
  4626.  
  4627.     % Create codewords array with one extra working space element and add padding
  4628.     /n c r mul k sub def
  4629.     /cws c r mul 1 add array def
  4630.     cws 0 n put
  4631.     cws 1 datcws putinterval
  4632.     cws m 1 add [ n m sub 1 sub {900} repeat ] putinterval
  4633.     cws n [ k {0} repeat 0 ] putinterval
  4634.  
  4635.     % Calculate the log and anti-log tables
  4636.     /rsalog [ 1 928 {dup 3 mul 929 mod} repeat ] def
  4637.     /rslog 929 array def
  4638.     1 1 928 {dup rsalog exch get exch rslog 3 1 roll put} for
  4639.  
  4640.     % Function to calculate the product in the field
  4641.     /rsprod {
  4642.         2 copy 0 ne exch 0 ne and {
  4643.             rslog exch get exch rslog exch get add 928 mod rsalog exch get
  4644.         } {
  4645.             pop pop 0
  4646.         } ifelse
  4647.     } bind def
  4648.  
  4649.     % Generate the coefficients
  4650.     /coeffs [ 1 k {0} repeat ] def
  4651.     1 1 k {
  4652.         /i exch def 
  4653.         coeffs i coeffs i 1 sub get put
  4654.         i 1 sub -1 1 {
  4655.             /j exch def
  4656.             coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod add 929 mod put
  4657.         } for 
  4658.         coeffs 0 coeffs 0 get rsalog i get rsprod put
  4659.     } for
  4660.     /coeffs coeffs 0 coeffs length 1 sub getinterval def
  4661.     1 2 coeffs length 1 sub {coeffs exch 2 copy get 929 exch sub put} for
  4662.  
  4663.     % Derive the error codewords
  4664.     0 1 n 1 sub {
  4665.         /t exch cws exch get cws n get add 929 mod def
  4666.         0 1 k 1 sub {
  4667.             /j exch def
  4668.             cws n j add cws n j add 1 add get 929 t coeffs k j sub 1 sub get mul 929 mod sub add 929 mod put
  4669.         } for
  4670.     } for
  4671.     n 1 n k add { dup cws exch 929 cws 5 -1 roll get sub put } for
  4672.  
  4673.     % Trim the working space from the end of the codewords
  4674.     /cws cws 0 cws length 1 sub getinterval def
  4675.  
  4676.     % Base 10 encoding of the bar space successions for the codewords in each cluster
  4677.     /clusters [
  4678.         [
  4679.             120256 125680 128380 120032 125560 128318 108736 119920 108640  86080 108592  86048
  4680.             110016 120560 125820 109792 120440 125758  88256 109680  88160  89536 110320 120700
  4681.              89312 110200 120638  89200 110140  89840 110460  89720 110398  89980 128506 119520
  4682.             125304 128190 107712 119408 125244 107616 119352  84032 107568 119324  84000 107544
  4683.              83984 108256 119672 125374  85184 108144 119612  85088 108088 119582  85040 108060
  4684.              85728 108408 119742  85616 108348  85560 108318  85880 108478  85820  85790 107200
  4685.             119152 125116 107104 119096 125086  83008 107056 119068  82976 107032  82960  82952
  4686.              83648 107376 119228  83552 107320 119198  83504 107292  83480  83468  83824 107452
  4687.              83768 107422  83740  83900 106848 118968 125022  82496 106800 118940  82464 106776
  4688.             118926  82448 106764  82440 106758  82784 106936 119006  82736 106908  82712 106894
  4689.              82700  82694 106974  82830  82240 106672 118876  82208 106648 118862  82192 106636
  4690.              82184 106630  82180  82352  82328  82316  82080 118830 106572 106566  82050 117472
  4691.             124280 127678 103616 117360 124220 103520 117304 124190  75840 103472  75808 104160
  4692.             117624 124350  76992 104048 117564  76896 103992  76848  76824  77536 104312 117694
  4693.              77424 104252  77368  77340  77688 104382  77628  77758 121536 126320 128700 121440
  4694.             126264 128670 111680 121392 126236 111648 121368 126222 111632 121356 103104 117104
  4695.             124092 112320 103008 117048 124062 112224 121656 126366  93248  74784 102936 117006
  4696.              93216 112152  93200  75456 103280 117180  93888  75360 103224 117150  93792 112440
  4697.             121758  93744  75288  93720  75632 103356  94064  75576 103326  94008 112542  93980
  4698.              75708  94140  75678  94110 121184 126136 128606 111168 121136 126108 111136 121112
  4699.             126094 111120 121100 111112 111108 102752 116920 123998 111456 102704 116892  91712
  4700.              74272 121244 116878  91680  74256 102668  91664 111372 102662  74244  74592 102840
  4701.             116958  92000  74544 102812  91952 111516 102798  91928  74508  74502  74680 102878
  4702.              92088  74652  92060  74638  92046  92126 110912 121008 126044 110880 120984 126030
  4703.             110864 120972 110856 120966 110852 110850  74048 102576 116828  90944  74016 102552
  4704.             116814  90912 111000 121038  90896  73992 102534  90888 110982  90884  74160 102620
  4705.              91056  74136 102606  91032 111054  91020  74118  91014  91100  91086 110752 120920
  4706.             125998 110736 120908 110728 120902 110724 110722  73888 102488 116782  90528  73872
  4707.             102476  90512 110796 102470  90504  73860  90500  73858  73944  90584  90572  90566
  4708.             120876 120870 110658 102444  73800  90312  90308  90306 101056 116080 123580 100960
  4709.             116024  70720 100912 115996  70688 100888  70672  70664  71360 101232 116156  71264
  4710.             101176 116126  71216 101148  71192  71180  71536 101308  71480 101278  71452  71612
  4711.              71582 118112 124600 127838 105024 118064 124572 104992 118040 124558 104976 118028
  4712.             104968 118022 100704 115896 123486 105312 100656 115868  79424  70176 118172 115854
  4713.              79392 105240 100620  79376  70152  79368  70496 100792 115934  79712  70448 118238
  4714.              79664 105372 100750  79640  70412  79628  70584 100830  79800  70556  79772  70542
  4715.              70622  79838 122176 126640 128860 122144 126616 128846 122128 126604 122120 126598
  4716.             122116 104768 117936 124508 113472 104736 126684 124494 113440 122264 126670 113424
  4717.             104712 117894 113416 122246 104706  69952 100528 115804  78656  69920 100504 115790
  4718.              96064  78624 104856 117966  96032 113560 122318 100486  96016  78600 104838  96008
  4719.              69890  70064 100572  78768  70040 100558  96176  78744 104910  96152 113614  70022
  4720.              78726  70108  78812  70094  96220  78798 122016 126552 128814 122000 126540 121992
  4721.             126534 121988 121986 104608 117848 124462 113056 104592 126574 113040 122060 117830
  4722.             113032 104580 113028 104578 113026  69792 100440 115758  78240  69776 100428  95136
  4723.              78224 104652 100422  95120 113100  69764  95112  78212  69762  78210  69848 100462
  4724.              78296  69836  95192  78284  69830  95180  78278  69870  95214 121936 126508 121928
  4725.             126502 121924 121922 104528 117804 112848 104520 117798 112840 121958 112836 104514
  4726.             112834  69712 100396  78032  69704 100390  94672  78024 104550  94664 112870  69698
  4727.              94660  78018  94658  78060  94700  94694 126486 121890 117782 104484 104482  69672
  4728.              77928  94440  69666  77922  99680  68160  99632  68128  99608 115342  68112  99596
  4729.              68104  99590  68448  99768 115422  68400  99740  68376  99726  68364  68358  68536
  4730.              99806  68508  68494  68574 101696 116400 123740 101664 116376 101648 116364 101640
  4731.             116358 101636  67904  99504 115292  72512  67872 116444 115278  72480 101784 116430
  4732.              72464  67848  99462  72456 101766  67842  68016  99548  72624  67992  99534  72600
  4733.             101838  72588  67974  68060  72668  68046  72654 118432 124760 127918 118416 124748
  4734.             118408 124742 118404 118402 101536 116312 105888 101520 116300 105872 118476 116294
  4735.             105864 101508 105860 101506 105858  67744  99416  72096  67728 116334  80800  72080
  4736.             101580  99398  80784 105932  67716  80776  72068  67714  72066  67800  99438  72152
  4737.              67788  80856  72140  67782  80844  72134  67822  72174  80878 126800 128940 126792
  4738.             128934 126788 126786 118352 124716 122576 126828 124710 122568 126822 122564 118338
  4739.             122562 101456 116268 105680 101448 116262 114128 105672 118374 114120 122598 101442
  4740.             114116 105666 114114  67664  99372  71888  67656  99366  80336  71880 101478  97232
  4741.              80328 105702  67650  97224 114150  71874  97220  67692  71916  67686  80364  71910
  4742.              97260  80358  97254 126760 128918 126756 126754 118312 124694 122472 126774 122468
  4743.             118306 122466 101416 116246 105576 101412 113896 105572 101410 113892 105570 113890
  4744.              67624  99350  71784 101430  80104  71780  67618  96744  80100  71778  96740  80098
  4745.              96738  71798  96758 126738 122420 122418 105524 113780 113778  71732  79988  96500
  4746.              96498  66880  66848  98968  66832  66824  66820  66992  66968  66956  66950  67036
  4747.              67022 100000  99984 115532  99976 115526  99972  99970  66720  98904  69024 100056
  4748.              98892  69008 100044  69000 100038  68996  66690  68994  66776  98926  69080 100078
  4749.              69068  66758  69062  66798  69102 116560 116552 116548 116546  99920 102096 116588
  4750.             115494 102088 116582 102084  99906 102082  66640  68816  66632  98854  73168  68808
  4751.              66628  73160  68804  66626  73156  68802  66668  68844  66662  73196  68838  73190
  4752.             124840 124836 124834 116520 118632 124854 118628 116514 118626  99880 115478 101992
  4753.             116534 106216 101988  99874 106212 101986 106210  66600  98838  68712  99894  72936
  4754.              68708  66594  81384  72932  68706  81380  72930  66614  68726  72950  81398 128980
  4755.             128978 124820 126900 124818 126898 116500 118580 116498 122740 118578 122738  99860
  4756.             101940  99858 106100 101938 114420
  4757.         ] [
  4758.             128352 129720 125504 128304 129692 125472 128280 129678 125456 128268 125448 128262
  4759.             125444 125792 128440 129758 120384 125744 128412 120352 125720 128398 120336 125708
  4760.             120328 125702 120324 120672 125880 128478 110144 120624 125852 110112 120600 125838
  4761.             110096 120588 110088 120582 110084 110432 120760 125918  89664 110384 120732  89632
  4762.             110360 120718  89616 110348  89608 110342  89952 110520 120798  89904 110492  89880
  4763.             110478  89868  90040 110558  90012  89998 125248 128176 129628 125216 128152 129614
  4764.             125200 128140 125192 128134 125188 125186 119616 125360 128220 119584 125336 128206
  4765.             119568 125324 119560 125318 119556 119554 108352 119728 125404 108320 119704 125390
  4766.             108304 119692 108296 119686 108292 108290  85824 108464 119772  85792 108440 119758
  4767.              85776 108428  85768 108422  85764  85936 108508  85912 108494  85900  85894  85980
  4768.              85966 125088 128088 129582 125072 128076 125064 128070 125060 125058 119200 125144
  4769.             128110 119184 125132 119176 125126 119172 119170 107424 119256 125166 107408 119244
  4770.             107400 119238 107396 107394  83872 107480 119278  83856 107468  83848 107462  83844
  4771.              83842  83928 107502  83916  83910  83950 125008 128044 125000 128038 124996 124994
  4772.             118992 125036 118984 125030 118980 118978 106960 119020 106952 119014 106948 106946
  4773.              82896 106988  82888 106982  82884  82882  82924  82918 124968 128022 124964 124962
  4774.             118888 124982 118884 118882 106728 118902 106724 106722  82408 106742  82404  82402
  4775.             124948 124946 118836 118834 106612 106610 124224 127664 129372 124192 127640 129358
  4776.             124176 127628 124168 127622 124164 124162 117568 124336 127708 117536 124312 127694
  4777.             117520 124300 117512 124294 117508 117506 104256 117680 124380 104224 117656 124366
  4778.             104208 117644 104200 117638 104196 104194  77632 104368 117724  77600 104344 117710
  4779.              77584 104332  77576 104326  77572  77744 104412  77720 104398  77708  77702  77788
  4780.              77774 128672 129880  93168 128656 129868  92664 128648 129862  92412 128644 128642
  4781.             124064 127576 129326 126368 124048 129902 126352 128716 127558 126344 124036 126340
  4782.             124034 126338 117152 124120 127598 121760 117136 124108 121744 126412 124102 121736
  4783.             117124 121732 117122 121730 103328 117208 124142 112544 103312 117196 112528 121804
  4784.             117190 112520 103300 112516 103298 112514  75680 103384 117230  94112  75664 103372
  4785.              94096 112588 103366  94088  75652  94084  75650  75736 103406  94168  75724  94156
  4786.              75718  94150  75758 128592 129836  91640 128584 129830  91388 128580  91262 128578
  4787.             123984 127532 126160 123976 127526 126152 128614 126148 123970 126146 116944 124012
  4788.             121296 116936 124006 121288 126182 121284 116930 121282 102864 116972 111568 102856
  4789.             116966 111560 121318 111556 102850 111554  74704 102892  92112  74696 102886  92104
  4790.             111590  92100  74690  92098  74732  92140  74726  92134 128552 129814  90876 128548
  4791.              90750 128546 123944 127510 126056 128566 126052 123938 126050 116840 123958 121064
  4792.             116836 121060 116834 121058 102632 116854 111080 121078 111076 102626 111074  74216
  4793.             102646  91112  74212  91108  74210  91106  74230  91126 128532  90494 128530 123924
  4794.             126004 123922 126002 116788 120948 116786 120946 102516 110836 102514 110834  73972
  4795.              90612  73970  90610 128522 123914 125978 116762 120890 102458 110714 123552 127320
  4796.             129198 123536 127308 123528 127302 123524 123522 116128 123608 127342 116112 123596
  4797.             116104 123590 116100 116098 101280 116184 123630 101264 116172 101256 116166 101252
  4798.             101250  71584 101336 116206  71568 101324  71560 101318  71556  71554  71640 101358
  4799.              71628  71622  71662 127824 129452  79352 127816 129446  79100 127812  78974 127810
  4800.             123472 127276 124624 123464 127270 124616 127846 124612 123458 124610 115920 123500
  4801.             118224 115912 123494 118216 124646 118212 115906 118210 100816 115948 105424 100808
  4802.             115942 105416 118246 105412 100802 105410  70608 100844  79824  70600 100838  79816
  4803.             105446  79812  70594  79810  70636  79852  70630  79846 129960  95728 113404 129956
  4804.              95480 113278 129954  95356  95294 127784 129430  78588 128872 129974  95996  78462
  4805.             128868 127778  95870 128866 123432 127254 124520 123428 126696 128886 123426 126692
  4806.             124514 126690 115816 123446 117992 115812 122344 117988 115810 122340 117986 122338
  4807.             100584 115830 104936 100580 113640 104932 100578 113636 104930 113634  70120 100598
  4808.              78824  70116  96232  78820  70114  96228  78818  96226  70134  78838 129940  94968
  4809.             113022 129938  94844  94782 127764  78206 128820 127762  95102 128818 123412 124468
  4810.             123410 126580 124466 126578 115764 117876 115762 122100 117874 122098 100468 104692
  4811.             100466 113140 104690 113138  69876  78324  69874  95220  78322  95218 129930  94588
  4812.              94526 127754 128794 123402 124442 126522 115738 117818 121978 100410 104570 112890
  4813.              69754  78074  94714  94398 123216 127148 123208 127142 123204 123202 115408 123244
  4814.             115400 123238 115396 115394  99792 115436  99784 115430  99780  99778  68560  99820
  4815.              68552  99814  68548  68546  68588  68582 127400 129238  72444 127396  72318 127394
  4816.             123176 127126 123752 123172 123748 123170 123746 115304 123190 116456 115300 116452
  4817.             115298 116450  99560 115318 101864  99556 101860  99554 101858  68072  99574  72680
  4818.              68068  72676  68066  72674  68086  72694 129492  80632 105854 129490  80508  80446
  4819.             127380  72062 127924 127378  80766 127922 123156 123700 123154 124788 123698 124786
  4820.             115252 116340 115250 118516 116338 118514  99444 101620  99442 105972 101618 105970
  4821.              67828  72180  67826  80884  72178  80882  97008 114044  96888 113982  96828  96798
  4822.             129482  80252 130010  97148  80190  97086 127370 127898 128954 123146 123674 124730
  4823.             126842 115226 116282 118394 122618  99386 101498 105722 114170  67706  71930  80378
  4824.              96632 113854  96572  96542  80062  96702  96444  96414  96350 123048 123044 123042
  4825.             115048 123062 115044 115042  99048 115062  99044  99042  67048  99062  67044  67042
  4826.              67062 127188  68990 127186 123028 123316 123026 123314 114996 115572 114994 115570
  4827.              98932 100084  98930 100082  66804  69108  66802  69106 129258  73084  73022 127178
  4828.             127450 123018 123290 123834 114970 115514 116602  98874  99962 102138  66682  68858
  4829.              73210  81272 106174  81212  81182  72894  81342  97648 114364  97592 114334  97564
  4830.              97550  81084  97724  81054  97694  97464 114270  97436  97422  80990  97502  97372
  4831.              97358  97326 114868 114866  98676  98674  66292  66290 123098 114842 115130  98618
  4832.              99194  66170  67322  69310  73404  73374  81592 106334  81564  81550  73310  81630
  4833.              97968 114524  97944 114510  97932  97926  81500  98012  81486  97998  97880 114478
  4834.              97868  97862  81454  97902  97836  97830  69470  73564  73550  81752 106414  81740
  4835.              81734  73518  81774  81708  81702
  4836.         ] [
  4837.             109536 120312  86976 109040 120060  86496 108792 119934  86256 108668  86136 129744
  4838.              89056 110072 129736  88560 109820 129732  88312 109694 129730  88188 128464 129772
  4839.              89592 128456 129766  89340 128452  89214 128450 125904 128492 125896 128486 125892
  4840.             125890 120784 125932 120776 125926 120772 120770 110544 120812 110536 120806 110532
  4841.              84928 108016 119548  84448 107768 119422  84208 107644  84088 107582  84028 129640
  4842.              85488 108284 129636  85240 108158 129634  85116  85054 128232 129654  85756 128228
  4843.              85630 128226 125416 128246 125412 125410 119784 125430 119780 119778 108520 119798
  4844.             108516 108514  83424 107256 119166  83184 107132  83064 107070  83004  82974 129588
  4845.              83704 107390 129586  83580  83518 128116  83838 128114 125172 125170 119284 119282
  4846.             107508 107506  82672 106876  82552 106814  82492  82462 129562  82812  82750 128058
  4847.             125050 119034  82296 106686  82236  82206  82366  82108  82078  76736 103920 117500
  4848.              76256 103672 117374  76016 103548  75896 103486  75836 129384  77296 104188 129380
  4849.              77048 104062 129378  76924  76862 127720 129398  77564 127716  77438 127714 124392
  4850.             127734 124388 124386 117736 124406 117732 117730 104424 117750 104420 104418 112096
  4851.             121592 126334  92608 111856 121468  92384 111736 121406  92272 111676  92216 111646
  4852.              92188  75232 103160 117118  93664  74992 103036  93424 112252 102974  93304  74812
  4853.              93244  74782  93214 129332  75512 103294 129908 129330  93944  75388 129906  93820
  4854.              75326  93758 127604  75646 128756 127602  94078 128754 124148 126452 124146 126450
  4855.             117236 121844 117234 121842 103412 103410  91584 111344 121212  91360 111224 121150
  4856.              91248 111164  91192 111134  91164  91150  74480 102780  91888  74360 102718  91768
  4857.             111422  91708  74270  91678 129306  74620 129850  92028  74558  91966 127546 128634
  4858.             124026 126202 116986 121338 102906  90848 110968 121022  90736 110908  90680 110878
  4859.              90652  90638  74104 102590  91000  74044  90940  74014  90910  74174  91070  90480
  4860.             110780  90424 110750  90396  90382  73916  90556  73886  90526  90296 110686  90268
  4861.              90254  73822  90334  90204  90190  71136 101112 116094  70896 100988  70776 100926
  4862.              70716  70686 129204  71416 101246 129202  71292  71230 127348  71550 127346 123636
  4863.             123634 116212 116210 101364 101362  79296 105200 118140  79072 105080 118078  78960
  4864.             105020  78904 104990  78876  78862  70384 100732  79600  70264 100670  79480 105278
  4865.              79420  70174  79390 129178  70524 129466  79740  70462  79678 127290 127866 123514
  4866.             124666 115962 118266 100858 113376 122232 126654  95424 113264 122172  95328 113208
  4867.             122142  95280 113180  95256 113166  95244  78560 104824 117950  95968  78448 104764
  4868.              95856 113468 104734  95800  78364  95772  78350  95758  70008 100542  78712  69948
  4869.              96120  78652  69918  96060  78622  96030  70078  78782  96190  94912 113008 122044
  4870.              94816 112952 122014  94768 112924  94744 112910  94732  94726  78192 104636  95088
  4871.              78136 104606  95032 113054  95004  78094  94990  69820  78268  69790  95164  78238
  4872.              95134  94560 112824 121950  94512 112796  94488 112782  94476  94470  78008 104542
  4873.              94648  77980  94620  77966  94606  69726  78046  94686  94384 112732  94360 112718
  4874.              94348  94342  77916  94428  77902  94414  94296 112686  94284  94278  77870  94318
  4875.              94252  94246  68336  99708  68216  99646  68156  68126  68476  68414 127162 123258
  4876.             115450  99834  72416 101752 116414  72304 101692  72248 101662  72220  72206  67960
  4877.              99518  72568  67900  72508  67870  72478  68030  72638  80576 105840 118460  80480
  4878.             105784 118430  80432 105756  80408 105742  80396  80390  72048 101564  80752  71992
  4879.             101534  80696  71964  80668  71950  80654  67772  72124  67742  80828  72094  80798
  4880.             114016 122552 126814  96832 113968 122524  96800 113944 122510  96784 113932  96776
  4881.             113926  96772  80224 105656 118366  97120  80176 105628  97072 114076 105614  97048
  4882.              80140  97036  80134  97030  71864 101470  80312  71836  97208  80284  71822  97180
  4883.              80270  97166  67678  71902  80350  97246  96576 113840 122460  96544 113816 122446
  4884.              96528 113804  96520 113798  96516  96514  80048 105564  96688  80024 105550  96664
  4885.             113870  96652  80006  96646  71772  80092  71758  96732  80078  96718  96416 113752
  4886.             122414  96400 113740  96392 113734  96388  96386  79960 105518  96472  79948  96460
  4887.              79942  96454  71726  79982  96494  96336 113708  96328 113702  96324  96322  79916
  4888.              96364  79910  96358  96296 113686  96292  96290  79894  96310  66936  99006  66876
  4889.              66846  67006  68976 100028  68920  99998  68892  68878  66748  69052  66718  69022
  4890.              73056 102072 116574  73008 102044  72984 102030  72972  72966  68792  99934  73144
  4891.              68764  73116  68750  73102  66654  68830  73182  81216 106160 118620  81184 106136
  4892.             118606  81168 106124  81160 106118  81156  81154  72880 101980  81328  72856 101966
  4893.              81304 106190  81292  72838  81286  68700  72924  68686  81372  72910  81358 114336
  4894.             122712 126894 114320 122700 114312 122694 114308 114306  81056 106072 118574  97696
  4895.              81040 106060  97680 114380 106054  97672  81028  97668  81026  97666  72792 101934
  4896.              81112  72780  97752  81100  72774  97740  81094  97734  68654  72814  81134  97774
  4897.             114256 122668 114248 122662 114244 114242  80976 106028  97488  80968 106022  97480
  4898.             114278  97476  80962  97474  72748  81004  72742  97516  80998  97510 114216 122646
  4899.             114212 114210  80936 106006  97384  80932  97380  80930  97378  72726  80950  97398
  4900.             114196 114194  80916  97332  80914  97330  66236  66206  67256  99166  67228  67214
  4901.              66142  67294  69296 100188  69272 100174  69260  69254  67164  69340  67150  69326
  4902.              73376 102232 116654  73360 102220  73352 102214  73348  73346  69208 100142  73432
  4903.             102254  73420  69190  73414  67118  69230  73454 106320 118700 106312 118694 106308
  4904.             106306  73296 102188  81616 106348 102182  81608  73284  81604  73282  81602  69164
  4905.              73324  69158  81644  73318  81638 122792 126934 122788 122786 106280 118678 114536
  4906.             106276 114532 106274 114530  73256 102166  81512  73252  98024  81508  73250  98020
  4907.              81506  98018  69142  73270  81526  98038 122772 122770 106260 114484 106258 114482
  4908.              73236  81460  73234  97908  81458  97906 122762 106250 114458  73226  81434  97850
  4909.              66396  66382  67416  99246  67404  67398  66350  67438  69456 100268  69448 100262
  4910.              69444  69442  67372  69484  67366  69478 102312 116694 102308 102306  69416 100246
  4911.              73576 102326  73572  69410  73570  67350  69430  73590 118740 118738 102292 106420
  4912.             102290 106418  69396  73524  69394  81780  73522  81778 118730 102282 106394  69386
  4913.              73498  81722  66476  66470  67496  99286  67492  67490  66454  67510 100308 100306
  4914.              67476  69556  67474  69554 116714
  4915.         ]
  4916.     ] def
  4917.  
  4918.     % Return the 17 bits for a codeword in a given cluster
  4919.     /cwtobits {
  4920.         clusters exch get exch get /v exch def
  4921.         [ 17 {0} repeat v 2 17 string cvrs {48 sub} forall ]
  4922.         dup length 17 sub 17 getinterval
  4923.     } bind def
  4924.  
  4925.     % Populate bitmap for the image
  4926.     compact {
  4927.         /rwid 17 c mul 17 add 17 add 1 add def
  4928.     } {
  4929.         /rwid 17 c mul 17 add 17 add 17 add 18 add def
  4930.     } ifelse
  4931.     /pixs rwid r mul array def
  4932.  
  4933.    0 1 r 1 sub {
  4934.         /i exch def
  4935.  
  4936.         i 3 mod 0 eq {
  4937.             /lcw i 3 idiv 30 mul r 1 sub 3 idiv add def
  4938.             /rcw i 3 idiv 30 mul c add 1 sub def
  4939.         } if
  4940.         i 3 mod 1 eq {
  4941.             /lcw i 3 idiv 30 mul eclevel 3 mul add r 1 sub 3 mod add def
  4942.             /rcw i 3 idiv 30 mul r 1 sub 3 idiv add def
  4943.         } if
  4944.         i 3 mod 2 eq {
  4945.             /lcw i 3 idiv 30 mul c add 1 sub def
  4946.             /rcw i 3 idiv 30 mul eclevel 3 mul add r 1 sub 3 mod add def
  4947.         } if
  4948.  
  4949.         pixs rwid i mul [
  4950.             1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 0 0
  4951.             lcw i 3 mod cwtobits {} forall
  4952.             cws c i mul c getinterval { i 3 mod cwtobits {} forall } forall
  4953.             compact {
  4954.                 1
  4955.             } {
  4956.                 rcw i 3 mod cwtobits {} forall
  4957.                 1 1 1 1 1 1 1 0 1 0 0 0 1 0 1 0 0 1
  4958.             } ifelse
  4959.         ] putinterval
  4960.  
  4961.     } for
  4962.  
  4963.     % Return the arguments
  4964.     <<
  4965.     /ren (renmatrix)
  4966.     /pixs pixs
  4967.     /pixx rwid
  4968.     /pixy r
  4969.     /height r 72 div rowmult mul
  4970.     /width rwid 72 div
  4971.     /opt options
  4972.     >>
  4973.  
  4974.     dontdraw not {//renmatrix exec} if
  4975.  
  4976.     end
  4977.  
  4978. } bind def
  4979. % --END ENCODER pdf417--
  4980.  
  4981. % --BEGIN ENCODER datamatrix--
  4982. % --DESC: Data Matrix
  4983. % --EXAM: ^142^164^186
  4984. % --EXOP: rows=32 columns=32
  4985. % --RNDR: renmatrix
  4986. /datamatrix {
  4987.  
  4988.     1 dict begin
  4989.  
  4990.     /options exch def
  4991.     /barcode exch def
  4992.  
  4993.     /dontdraw false def
  4994.     /columns 0 def
  4995.     /rows 0 def
  4996.  
  4997.     % Parse the input options
  4998.     options type /stringtype eq {
  4999.         1 dict begin
  5000.         options {
  5001.             token false eq {exit} if dup length string cvs (=) search
  5002.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  5003.         } loop
  5004.         currentdict end /options exch def
  5005.     } if
  5006.     options {def} forall
  5007.  
  5008.     /columns columns cvi def
  5009.     /rows rows cvi def
  5010.  
  5011.     % Split the input barcode into an array of codewords
  5012.     /cws barcode length array def
  5013.     /i 0 def /j 0 def
  5014.     { % loop
  5015.         i barcode length eq {exit} if
  5016.         /cw barcode i 1 add 3 getinterval cvi def
  5017.         cws j cw put
  5018.         /i i 4 add def
  5019.         /j j 1 add def
  5020.     } loop
  5021.     /cws cws 0 j getinterval def
  5022.  
  5023.     % Basic metrics for the each symbol
  5024.     %    rows  cols  regh  regv  rscw  rsbl
  5025.     /metrics [
  5026.         % Standard square symbols
  5027.         [  10    10     1     1     5     1 ]
  5028.         [  12    12     1     1     7     1 ]
  5029.         [  14    14     1     1    10     1 ]
  5030.         [  16    16     1     1    12     1 ]
  5031.         [  18    18     1     1    14     1 ]
  5032.         [  20    20     1     1    18     1 ] 
  5033.         [  22    22     1     1    20     1 ]
  5034.         [  24    24     1     1    24     1 ]
  5035.         [  26    26     1     1    28     1 ]
  5036.         [  32    32     2     2    36     1 ]
  5037.         [  36    36     2     2    42     1 ]
  5038.         [  40    40     2     2    48     1 ]
  5039.         [  44    44     2     2    56     1 ]
  5040.         [  48    48     2     2    68     1 ]
  5041.         [  52    52     2     2    84     2 ]
  5042.         [  64    64     4     4   112     2 ]
  5043.         [  72    72     4     4   144     4 ]
  5044.         [  80    80     4     4   192     4 ]
  5045.         [  88    88     4     4   224     4 ]
  5046.         [  96    96     4     4   272     4 ]
  5047.         [ 104   104     4     4   336     6 ]
  5048.         [ 120   120     6     6   408     6 ]
  5049.         [ 132   132     6     6   496     8 ]
  5050.         [ 144   144     6     6   620    10 ]
  5051.         % Optional rectangular symbols
  5052.         [   8    18     1     1     7     1 ]
  5053.         [   8    32     1     2    11     1 ]
  5054.         [  12    26     1     1    14     1 ]
  5055.         [  12    36     1     2    18     1 ]
  5056.         [  16    36     1     2    24     1 ]
  5057.         [  16    48     1     2    28     1 ]
  5058.     ] def
  5059.  
  5060.     % Select metrics of an appropriate symbol
  5061.     /urows rows def
  5062.     /ucols columns def
  5063.     /i 0 def
  5064.     { % loop
  5065.         /m metrics i get def
  5066.         /rows m 0 get def                          % Rows in symbol
  5067.         /cols m 1 get def                          % Columns in symbol
  5068.         /regh m 2 get def                          % Horizontal regions
  5069.         /regv m 3 get def                          % Vertical regions
  5070.         /rscw m 4 get def                          % Error correction codewords
  5071.         /rsbl m 5 get def                          % Error correction blocks
  5072.         /mrows rows 2 regh mul sub def             % Rows in the mapping matrix
  5073.         /mcols cols 2 regv mul sub def             % Columns in the mapping matrix
  5074.         /rrows mrows regh idiv def                 % Rows per region
  5075.         /rcols mcols regv idiv def                 % Columns per region
  5076.         /ncws mrows mcols mul 8 idiv rscw sub def  % Data codewords
  5077.         /okay true def
  5078.         cws length ncws gt           {/okay false def} if
  5079.         urows 0 ne urows rows ne and {/okay false def} if
  5080.         ucols 0 ne ucols cols ne and {/okay false def} if
  5081.         okay {exit} if
  5082.         /i i 1 add def
  5083.     } loop
  5084.  
  5085.     % Extend cws to ncws codewords by addition of pseudo-randomised pad characters
  5086.     cws length ncws lt {
  5087.         /datlen cws length def
  5088.         /cws [ cws {} forall ncws datlen sub {129} repeat ] def
  5089.         datlen 1 add 1 ncws 1 sub {
  5090.             /i exch def
  5091.             i 1 add 149 mul 253 mod 1 add 129 add
  5092.             dup 254 gt {254 sub} if
  5093.             cws exch i exch put
  5094.         } for
  5095.     } if
  5096.  
  5097.     % De-interleave the codewords into blocks
  5098.     /cwbs rsbl array def  % Array of data codeword blocks
  5099.     /ecbs rsbl array def  % Array of error correction blocks
  5100.     0 1 rsbl 1 sub {
  5101.         /i exch def
  5102.         cws length 1558 ne {
  5103.             /cwbsize cws length rsbl idiv def
  5104.         } {
  5105.             i 7 le {/cwbsize 156 def} {/cwbsize 155 def} ifelse
  5106.         } ifelse
  5107.         /cwb cwbsize array def 
  5108.         0 1 cwbsize 1 sub {
  5109.             /j exch def
  5110.             cwb j cws j rsbl mul i add get put
  5111.         } for 
  5112.         cwbs i cwb put
  5113.         ecbs i [ rscw rsbl idiv {0} repeat ] put
  5114.     } for
  5115.  
  5116.     % Calculate the log and anti-log tables
  5117.     /rsalog [ 1 255 { dup 2 mul dup 256 ge {301 xor} if } repeat ] def
  5118.     /rslog 256 array def
  5119.     1 1 255 {dup rsalog exch get exch rslog 3 1 roll put} for
  5120.  
  5121.     % Function to calculate the product in the field
  5122.     /rsprod {
  5123.         2 copy 0 ne exch 0 ne and { 
  5124.             rslog exch get exch rslog exch get add 255 mod rsalog exch get
  5125.         } {
  5126.             pop pop 0
  5127.         } ifelse
  5128.     } bind def
  5129.  
  5130.     % Generate the coefficients
  5131.     /coeffs [ 1 rscw rsbl idiv {0} repeat ] def
  5132.     1 1 rscw rsbl idiv {
  5133.         /i exch def 
  5134.         coeffs i coeffs i 1 sub get put
  5135.         i 1 sub -1 1 {
  5136.             /j exch def
  5137.             coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put
  5138.         } for 
  5139.         coeffs 0 coeffs 0 get rsalog i get rsprod put
  5140.     } for
  5141.     /coeffs coeffs 0 coeffs length 1 sub getinterval def
  5142.  
  5143.     % Calculate the error correction codewords for each block
  5144.     0 1 cwbs length 1 sub {
  5145.         /i exch def
  5146.         /cwb cwbs i get def
  5147.         /ecb ecbs i get def
  5148.         0 1 cwb length 1 sub {
  5149.             /t exch cwb exch get ecb 0 get xor def 
  5150.             ecb length 1 sub -1 0 {
  5151.                 /j exch def
  5152.                 /p ecb length j sub 1 sub def
  5153.                 ecb p t coeffs j get rsprod put
  5154.                 j 0 gt { ecb p ecb p 1 add get ecb p get xor put } if
  5155.             } for 
  5156.         } for
  5157.     } for
  5158.  
  5159.     % Strange fixup for 144x144 symbols
  5160.     ncws 1558 eq {
  5161.         /ecbs [ ecbs 8 2 getinterval {} forall ecbs 0 8 getinterval {} forall ] def
  5162.     } if
  5163.  
  5164.     % Extend codewords with the interleaved error correction codes
  5165.     /cws [ cws {} forall rscw {0} repeat ] def
  5166.     0 1 rscw 1 sub {
  5167.         /i exch def
  5168.         cws ncws i add ecbs i rsbl mod get i rsbl idiv get put
  5169.     } for
  5170.  
  5171.     % Place the codewords into the matrix
  5172.     /module {
  5173.         % cw row col shape
  5174.         4 -1 roll 
  5175.         (00000000) 8 string copy dup 3 -1 roll 2 8 string cvrs 
  5176.         dup length 8 exch sub exch putinterval 
  5177.         7 -1 0 {1 index exch get 48 sub exch} for pop
  5178.         11 -3 roll
  5179.         % 1 2 4 8 16 32 64 128 row col shape
  5180.         {  % Place each bit of the codeword in the shape, MSB first
  5181.             exec
  5182.             1 index 0 lt {
  5183.                 exch mrows add exch
  5184.                 4 mrows 4 add 8 mod sub add
  5185.             } if
  5186.             dup 0 lt {
  5187.                 mcols add exch
  5188.                 4 mcols 4 add 8 mod sub add exch
  5189.             } if
  5190.             exch mcols mul add
  5191.             mmat exch 5 -1 roll put
  5192.         } forall
  5193.     } bind def
  5194.  
  5195.     % Placement patterns
  5196.     /dmn [
  5197.         { 2 copy 2 sub exch 2 sub exch } bind  { 2 copy 1 sub exch 2 sub exch } bind
  5198.         { 2 copy 2 sub exch 1 sub exch } bind  { 2 copy 1 sub exch 1 sub exch } bind
  5199.         { 2 copy exch 1 sub exch } bind        { 2 copy 2 sub } bind
  5200.         { 2 copy 1 sub } bind                  { 2 copy } bind
  5201.     ] def
  5202.     
  5203.     /dmc1 [
  5204.         { mrows 1 sub 0 } bind  { mrows 1 sub 1 } bind
  5205.         { mrows 1 sub 2 } bind  { 0 mcols 2 sub } bind
  5206.         { 0 mcols 1 sub } bind  { 1 mcols 1 sub } bind
  5207.         { 2 mcols 1 sub } bind  { 3 mcols 1 sub } bind
  5208.     ] def
  5209.     
  5210.     /dmc2 [
  5211.         { mrows 3 sub 0 } bind  { mrows 2 sub 0 } bind
  5212.         { mrows 1 sub 0 } bind  { 0 mcols 4 sub } bind
  5213.         { 0 mcols 3 sub } bind  { 0 mcols 2 sub } bind
  5214.         { 0 mcols 1 sub } bind  { 1 mcols 1 sub } bind
  5215.     ] def
  5216.     
  5217.     /dmc3 [
  5218.         { mrows 3 sub 0 } bind  { mrows 2 sub 0 } bind
  5219.         { mrows 1 sub 0 } bind  { 0 mcols 2 sub } bind
  5220.         { 0 mcols 1 sub } bind  { 1 mcols 1 sub } bind
  5221.         { 2 mcols 1 sub } bind  { 3 mcols 1 sub } bind
  5222.     ] def
  5223.     
  5224.     /dmc4 [
  5225.         { mrows 1 sub 0 } bind  { mrows 1 sub mcols 1 sub } bind
  5226.         { 0 mcols 3 sub } bind  { 0 mcols 2 sub } bind
  5227.         { 0 mcols 1 sub } bind  { 1 mcols 3 sub } bind
  5228.         { 1 mcols 2 sub } bind  { 1 mcols 1 sub } bind
  5229.     ] def
  5230.  
  5231.     /mmat [ mrows mcols mul {-1} repeat ] def
  5232.     cws length 1 sub -1 0 {cws exch get} for  % Reverse cws onto stack
  5233.     4 0  % Starting row and column
  5234.     { % loop
  5235.         2 copy 0 eq exch mrows eq and {
  5236.             dmc1 module
  5237.         } if
  5238.         2 copy 0 eq exch mrows 2 sub eq and mcols 4 mod 0 ne and {
  5239.             dmc2 module
  5240.         } if
  5241.         2 copy 0 eq exch mrows 2 sub eq and mcols 8 mod 4 eq and {
  5242.             dmc3 module
  5243.         } if
  5244.         2 copy 2 eq exch mrows 4 add eq and mcols 8 mod 0 eq and {
  5245.             dmc4 module
  5246.         } if
  5247.  
  5248.         { % loop for sweeping upwards
  5249.             2 copy 0 ge exch mrows lt and {
  5250.                 2 copy exch mcols mul add mmat exch get -1 eq {
  5251.                     dmn module
  5252.                 } if
  5253.             } if
  5254.             2 add exch 2 sub exch
  5255.             2 copy mcols lt exch 0 ge and not {exit} if
  5256.         } loop
  5257.         3 add exch 1 add exch
  5258.  
  5259.         { % loop for sweeping downwards
  5260.             2 copy mcols lt exch 0 ge and {
  5261.                 2 copy exch mcols mul add mmat exch get -1 eq {
  5262.                     dmn module
  5263.                 } if
  5264.             } if
  5265.             2 sub exch 2 add exch
  5266.             2 copy 0 ge exch mrows lt and not {exit} if
  5267.         } loop
  5268.         1 add exch 3 add exch
  5269.  
  5270.         2 copy mcols lt exch mrows lt or not {pop pop exit} if
  5271.  
  5272.     } loop
  5273.  
  5274.     % Set checker pattern if required
  5275.     mmat mrows mcols mul 1 sub get -1 eq {
  5276.         mmat mrows mcols 1 sub mul 2 sub [1 0] putinterval
  5277.         mmat mrows mcols mul 2 sub [0 1] putinterval
  5278.     } if
  5279.  
  5280.     % Place the modules onto a pixel map between alignment patterns
  5281.     /pixs rows cols mul array def
  5282.     /cwpos 0 def
  5283.     0 1 rows 1 sub {
  5284.         /i exch def
  5285.         i rrows 2 add mod 0 eq { pixs i cols mul [ cols 2 idiv {1 0} repeat ] putinterval } if  
  5286.         i rrows 2 add mod rrows 1 add eq { pixs i cols mul [ cols {1} repeat ] putinterval } if 
  5287.         i rrows 2 add mod 0 ne i rrows 2 add mod rrows 1 add ne and {
  5288.             0 1 cols 1 sub {
  5289.                 /j exch def
  5290.                 j rcols 2 add mod 0 eq { pixs i cols mul j add 1 put } if
  5291.                 j rcols 2 add mod rcols 1 add eq { pixs i cols mul j add i 2 mod put } if
  5292.                 j rcols 2 add mod 0 ne j rcols 2 add mod rcols 1 add ne and {
  5293.                     pixs i cols mul j add mmat cwpos get put
  5294.                     /cwpos cwpos 1 add def
  5295.                 } if
  5296.             } for
  5297.         } if 
  5298.     } for
  5299.  
  5300.     % Return the arguments
  5301.     <<
  5302.     /ren (renmatrix)
  5303.     /pixs pixs
  5304.     /pixx cols
  5305.     /pixy rows
  5306.     /height rows 72 div 1.5 mul
  5307.     /width cols 72 div 1.5 mul
  5308.     /opt options
  5309.     >>
  5310.  
  5311.     dontdraw not {//renmatrix exec} if
  5312.  
  5313.     end
  5314.  
  5315. } bind def
  5316. % --END ENCODER datamatrix--
  5317.  
  5318. % --BEGIN ENCODER qrcode--
  5319. % --DESC: QR Code
  5320. % --EXAM: 000100000010000000001100010101100110000110000
  5321. % --EXOP: version=1 eclevel=M
  5322. % --RNDR: renmatrix
  5323. /qrcode {
  5324.  
  5325.     1 dict begin
  5326.  
  5327.     /options exch def
  5328.     /barcode exch def
  5329.  
  5330.     /dontdraw false def
  5331.     /format (full) def     % full or micro
  5332.     /version (unset) def
  5333.     /eclevel (L) def       % L, M, Q or H
  5334.  
  5335.     % Parse the input options
  5336.     options type /stringtype eq {
  5337.         1 dict begin
  5338.         options {
  5339.             token false eq {exit} if dup length string cvs (=) search
  5340.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  5341.         } loop
  5342.         currentdict end /options exch def
  5343.     } if
  5344.     options {def} forall
  5345.  
  5346.     % Convert from input into message bitstream
  5347.     /msgbits barcode def 
  5348.  
  5349.     % Lookup the most appropriate symbol specification
  5350.     /metrics [
  5351.         % format   vers  size align modules    error codewords        error correction blocks 
  5352.         %                                      L    M    Q    H       L1 L2 M1 M2 Q1 Q2 H1 H2
  5353.         [ (micro)  (M1)   11  98 99     36  [   2   99   99   99 ]  [  1  0 99 99 99 99 99 99 ] ]
  5354.         [ (micro)  (M2)   13  98 99     80  [   5    6   99   99 ]  [  1  0  1  0 99 99 99 99 ] ]
  5355.         [ (micro)  (M3)   15  98 99    132  [   6    8   99   99 ]  [  1  0  1  0 99 99 99 99 ] ]
  5356.         [ (micro)  (M4)   17  98 99    192  [   8   10   14   99 ]  [  1  0  1  0  1  0 99 99 ] ]
  5357.         [ (full)   (1)    21  98 99    208  [   7   10   13   17 ]  [  1  0  1  0  1  0  1  0 ] ]
  5358.         [ (full)   (2)    25  18 99    359  [  10   16   22   28 ]  [  1  0  1  0  1  0  1  0 ] ]
  5359.         [ (full)   (3)    29  22 99    567  [  15   26   36   44 ]  [  1  0  1  0  2  0  2  0 ] ]
  5360.         [ (full)   (4)    33  26 99    807  [  20   36   52   64 ]  [  1  0  2  0  2  0  4  0 ] ]
  5361.         [ (full)   (5)    37  30 99   1079  [  26   48   72   88 ]  [  1  0  2  0  2  2  2  2 ] ]
  5362.         [ (full)   (6)    41  34 99   1383  [  36   64   96  112 ]  [  2  0  4  0  4  0  4  0 ] ]
  5363.         [ (full)   (7)    45  22 38   1568  [  40   72  108  130 ]  [  2  0  4  0  2  4  4  1 ] ]
  5364.         [ (full)   (8)    49  24 42   1936  [  48   88  132  156 ]  [  2  0  2  2  4  2  4  2 ] ]
  5365.         [ (full)   (9)    53  26 46   2336  [  60  110  160  192 ]  [  2  0  3  2  4  4  4  4 ] ]
  5366.         [ (full)   (10)   57  28 50   2768  [  72  130  192  224 ]  [  2  2  4  1  6  2  6  2 ] ]
  5367.         [ (full)   (11)   61  30 54   3232  [  80  150  224  264 ]  [  4  0  1  4  4  4  3  8 ] ]
  5368.         [ (full)   (12)   65  32 58   3728  [  96  176  260  308 ]  [  2  2  6  2  4  6  7  4 ] ]
  5369.         [ (full)   (13)   69  34 62   4256  [ 104  198  288  352 ]  [  4  0  8  1  8  4 12  4 ] ]
  5370.         [ (full)   (14)   73  26 46   4651  [ 120  216  320  384 ]  [  3  1  4  5 11  5 11  5 ] ]
  5371.         [ (full)   (15)   77  26 48   5243  [ 132  240  360  432 ]  [  5  1  5  5  5  7 11  7 ] ]
  5372.         [ (full)   (16)   81  26 50   5867  [ 144  280  408  480 ]  [  5  1  7  3 15  2  3 13 ] ]
  5373.         [ (full)   (17)   85  30 54   6523  [ 168  308  448  532 ]  [  1  5 10  1  1 15  2 17 ] ]
  5374.         [ (full)   (18)   89  30 56   7211  [ 180  338  504  588 ]  [  5  1  9  4 17  1  2 19 ] ]
  5375.         [ (full)   (19)   93  30 58   7931  [ 196  364  546  650 ]  [  3  4  3 11 17  4  9 16 ] ]
  5376.         [ (full)   (20)   97  34 62   8683  [ 224  416  600  700 ]  [  3  5  3 13 15  5 15 10 ] ]
  5377.         [ (full)   (21)  101  28 50   9252  [ 224  442  644  750 ]  [  4  4 17  0 17  6 19  6 ] ]
  5378.         [ (full)   (22)  105  26 50  10068  [ 252  476  690  816 ]  [  2  7 17  0  7 16 34  0 ] ]
  5379.         [ (full)   (23)  109  30 54  10916  [ 270  504  750  900 ]  [  4  5  4 14 11 14 16 14 ] ]
  5380.         [ (full)   (24)  113  28 54  11796  [ 300  560  810  960 ]  [  6  4  6 14 11 16 30  2 ] ]
  5381.         [ (full)   (25)  117  32 58  12708  [ 312  588  870 1050 ]  [  8  4  8 13  7 22 22 13 ] ]
  5382.         [ (full)   (26)  121  30 58  13652  [ 336  644  952 1110 ]  [ 10  2 19  4 28  6 33  4 ] ]
  5383.         [ (full)   (27)  125  34 62  14628  [ 360  700 1020 1200 ]  [  8  4 22  3  8 26 12 28 ] ]
  5384.         [ (full)   (28)  129  26 50  15371  [ 390  728 1050 1260 ]  [  3 10  3 23  4 31 11 31 ] ]
  5385.         [ (full)   (29)  133  30 54  16411  [ 420  784 1140 1350 ]  [  7  7 21  7  1 37 19 26 ] ]
  5386.         [ (full)   (30)  137  26 52  17483  [ 450  812 1200 1440 ]  [  5 10 19 10 15 25 23 25 ] ]
  5387.         [ (full)   (31)  141  30 56  18587  [ 480  868 1290 1530 ]  [ 13  3  2 29 42  1 23 28 ] ]
  5388.         [ (full)   (32)  145  34 60  19723  [ 510  924 1350 1620 ]  [ 17  0 10 23 10 35 19 35 ] ]
  5389.         [ (full)   (33)  149  30 58  20891  [ 540  980 1440 1710 ]  [ 17  1 14 21 29 19 11 46 ] ]
  5390.         [ (full)   (34)  153  34 62  22091  [ 570 1036 1530 1800 ]  [ 13  6 14 23 44  7 59  1 ] ]
  5391.         [ (full)   (35)  157  30 54  23008  [ 570 1064 1590 1890 ]  [ 12  7 12 26 39 14 22 41 ] ]
  5392.         [ (full)   (36)  161  24 50  24272  [ 600 1120 1680 1980 ]  [  6 14  6 34 46 10  2 64 ] ]
  5393.         [ (full)   (37)  165  28 54  25568  [ 630 1204 1770 2100 ]  [ 17  4 29 14 49 10 24 46 ] ]
  5394.         [ (full)   (38)  169  32 58  26896  [ 660 1260 1860 2220 ]  [  4 18 13 32 48 14 42 32 ] ]
  5395.         [ (full)   (39)  173  26 54  28256  [ 720 1316 1950 2310 ]  [ 20  4 40  7 43 22 10 67 ] ]
  5396.         [ (full)   (40)  177  30 58  29648  [ 750 1372 2040 2430 ]  [ 19  6 18 31 34 34 20 61 ] ]
  5397.     ] def
  5398.  
  5399.     /eclval (LMQH) eclevel search pop length exch pop exch pop def
  5400.     /i 0 def
  5401.     { % loop
  5402.         /m metrics i get def
  5403.         /frmt m 0 get def                             % Format of the symbol
  5404.         /vers m 1 get def                             % Version of symbol
  5405.         /size m 2 get def                             % Length of side
  5406.         /asp2 m 3 get def                             % Position of second alignment symbol
  5407.         /asp3 m 4 get def                             % Position of third alignment symbol
  5408.         /nmod m 5 get def                             % Number of modules
  5409.         /ncws nmod 8 idiv def                         % Total number of codewords
  5410.         /rbit nmod 8 mod def                          % Number of remainder bits
  5411.         /lc4b false def                               % Last data codeword is 4 bits long
  5412.         size 11 eq size 15 eq or {                    % Adjustments for M1 and M3 symbols
  5413.             /ncws ncws 1 add def
  5414.             /rbit 0 def
  5415.             /lc4b true def
  5416.         } if
  5417.         /ecws m 6 get eclval get def                  % Number of error correction codewords
  5418.         /dcws ncws ecws sub def                       % Number of data codewords
  5419.         /dmod dcws 8 mul lc4b {4} {0} ifelse sub def  % Number of data modules
  5420.         /ecb1 m 7 get eclval 2 mul get def            % First error correction blocks
  5421.         /ecb2 m 7 get eclval 2 mul 1 add get def      % Second error correction blocks
  5422.         /dcpb dcws ecb1 ecb2 add idiv def             % Base data codewords per block
  5423.         /ecpb ncws ecb1 ecb2 add idiv dcpb sub def    % Error correction codewords per block
  5424.         /okay true def
  5425.         version (unset) ne version vers ne and {/okay false def} if
  5426.         version (unset) eq format frmt ne and {/okay false def} if
  5427.         msgbits length dmod gt {/okay false def} if
  5428.         okay {exit} if
  5429.         /i i 1 add def
  5430.     } loop
  5431.     /format frmt def
  5432.     /version vers def
  5433.  
  5434.     % Expand the message bits by adding padding as necessary
  5435.     /pad dmod string def
  5436.     0 4 dmod 1 sub {pad exch (0000) putinterval} for
  5437.     pad 0 msgbits putinterval
  5438.     /padstrs [ (11101100) (00010001) ] def
  5439.     /padnum 0 def
  5440.     msgbits length 8 div ceiling 8 mul cvi 8 dmod lc4b {5} {1} ifelse sub {
  5441.         pad exch padstrs padnum get putinterval 
  5442.         /padnum padnum 1 add 2 mod def
  5443.     } for
  5444.  
  5445.     % Evaluate the padded message into codewords
  5446.     /cws dcws array def 
  5447.     0 1 cws length 1 sub {
  5448.         /c exch def
  5449.         /bpcw 8 def
  5450.         lc4b c cws length 1 sub eq and {/bpcw 4 def} if
  5451.         /cwb pad c 8 mul bpcw getinterval def
  5452.         /cw 0 def
  5453.         0 1 bpcw 1 sub {
  5454.             /i exch def
  5455.             /cw cw 2 bpcw i sub 1 sub exp cvi cwb i get 48 sub mul add def
  5456.         } for 
  5457.         cws c cw put
  5458.     } for 
  5459.  
  5460.     % Calculate the log and anti-log tables
  5461.     /rsalog [ 1 255 { dup 2 mul dup 256 ge {285 xor} if } repeat ] def
  5462.     /rslog 256 array def
  5463.     1 1 255 {dup rsalog exch get exch rslog 3 1 roll put} for
  5464.  
  5465.     % Function to calculate the product in the field
  5466.     /rsprod {
  5467.         2 copy 0 ne exch 0 ne and { 
  5468.             rslog exch get exch rslog exch get add 255 mod rsalog exch get
  5469.         } {
  5470.             pop pop 0
  5471.         } ifelse
  5472.     } bind def
  5473.  
  5474.     % Generate the coefficients for the Reed-Solomon algorithm
  5475.     /coeffs [ 1 ecpb {0} repeat ] def
  5476.     0 1 ecpb 1 sub {
  5477.         /i exch def 
  5478.         coeffs i 1 add coeffs i get put
  5479.         i -1 1 {
  5480.             /j exch def
  5481.             coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put
  5482.         } for 
  5483.         coeffs 0 coeffs 0 get rsalog i get rsprod put
  5484.     } for
  5485.     /coeffs coeffs 0 coeffs length 1 sub getinterval def
  5486.  
  5487.     % Reed-Solomon algorithm to derive the error correction codewords
  5488.     /rscodes {
  5489.         /rscws exch def
  5490.         /rsnd rscws length def
  5491.         /rscws [ rscws {} forall ecpb {0} repeat ] def
  5492.         0 1 rsnd 1 sub {
  5493.             /m exch def
  5494.             /k rscws m get def
  5495.             0 1 ecpb 1 sub {
  5496.                 /j exch def
  5497.                 rscws m j add 1 add coeffs ecpb j sub 1 sub get k rsprod rscws m j add 1 add get xor put
  5498.             } for
  5499.         } for
  5500.         rscws rsnd ecpb getinterval
  5501.     } bind def
  5502.  
  5503.     % Divide codewords into two groups of blocks and calculate the error correction codewords
  5504.     /dcwsb ecb1 ecb2 add array def
  5505.     /ecwsb ecb1 ecb2 add array def
  5506.     0 1 ecb1 1 sub {  % First group of blocks has smaller number of data codewords
  5507.         /i exch def
  5508.         dcwsb i cws i dcpb mul dcpb getinterval put
  5509.         ecwsb i dcwsb i get rscodes put
  5510.     } for
  5511.     0 1 ecb2 1 sub {  % Second group of blocks has larger number of data codewords
  5512.         /i exch def
  5513.         dcwsb ecb1 i add cws ecb1 dcpb mul i dcpb 1 add mul add dcpb 1 add getinterval put
  5514.         ecwsb ecb1 i add dcwsb ecb1 i add get rscodes put
  5515.     } for
  5516.     
  5517.     % Reassemble the codewords
  5518.     /cws ncws array def
  5519.     /cw 0 def
  5520.     0 1 dcpb {  % Interleave the data codeword blocks
  5521.         /i exch def
  5522.         0 1 ecb1 ecb2 add 1 sub {
  5523.             /j exch def
  5524.             i dcwsb j get length lt {  % Ignore the end of short blocks
  5525.                 cws cw dcwsb j get i get put
  5526.                 /cw cw 1 add def
  5527.             } if
  5528.         } for
  5529.     } for
  5530.     0 1 ecpb 1 sub {  % Interleave the error codeword blocks
  5531.         /i exch def
  5532.         0 1 ecb1 ecb2 add 1 sub {
  5533.             /j exch def
  5534.             cws cw ecwsb j get i get put
  5535.             /cw cw 1 add def
  5536.         } for
  5537.     } for
  5538.     
  5539.     % Extend codewords by one if there are remainder bits
  5540.     rbit 0 gt {
  5541.         /pad cws length 1 add array def
  5542.         pad 0 cws putinterval
  5543.         pad pad length 1 sub 0 put
  5544.         /cws pad def
  5545.     } if
  5546.  
  5547.     % Fixups for the short final data byte in M1 and M3 symbols
  5548.     lc4b {
  5549.         dcws 1 sub 1 ncws 2 sub {
  5550.             /i exch def
  5551.             cws i cws i get 15 and 4 bitshift put
  5552.             cws i cws i 1 add get -4 bitshift 15 and cws i get or put
  5553.         } for
  5554.         cws ncws 1 sub cws ncws 1 sub get 15 and 4 bitshift put
  5555.     } if
  5556.  
  5557.     % Create the bitmap
  5558.     /pixs [ size size mul {-1} repeat ] def
  5559.     /qmv {size mul add} bind def
  5560.     
  5561.     % Finder patterns
  5562.     /fpat [
  5563.         [ 1 1 1 1 1 1 1 0 ]
  5564.         [ 1 0 0 0 0 0 1 0 ]
  5565.         [ 1 0 1 1 1 0 1 0 ]
  5566.         [ 1 0 1 1 1 0 1 0 ]
  5567.         [ 1 0 1 1 1 0 1 0 ]
  5568.         [ 1 0 0 0 0 0 1 0 ]
  5569.         [ 1 1 1 1 1 1 1 0 ]
  5570.         [ 0 0 0 0 0 0 0 0 ]
  5571.     ] def
  5572.     0 1 fpat length 1 sub {
  5573.       /y exch def
  5574.       0 1 fpat 0 get length 1 sub {
  5575.         /x exch def
  5576.         /fpb fpat y get x get def
  5577.         pixs x y qmv fpb put
  5578.         format (full) eq {
  5579.             pixs size x sub 1 sub y qmv fpb put
  5580.             pixs x size y sub 1 sub qmv fpb put
  5581.         } if
  5582.       } for
  5583.     } for
  5584.     
  5585.     % Alignment patterns
  5586.     /algnpat [
  5587.         [ 1 1 1 1 1 ]
  5588.         [ 1 0 0 0 1 ]
  5589.         [ 1 0 1 0 1 ]
  5590.         [ 1 0 0 0 1 ]
  5591.         [ 1 1 1 1 1 ]
  5592.     ] def
  5593.     /putalgnpat {
  5594.         /py exch def
  5595.         /px exch def
  5596.         0 1 4 {
  5597.             /pb exch def
  5598.             0 1 4 {
  5599.                 /pa exch def
  5600.                 pixs px pa add py pb add qmv algnpat pb get pa get put
  5601.             } for
  5602.         } for
  5603.     } bind def
  5604.     asp2 2 sub asp3 asp2 sub size 13 sub {
  5605.         /i exch def
  5606.         i 4 putalgnpat
  5607.         4 i putalgnpat
  5608.     } for
  5609.     asp2 2 sub asp3 asp2 sub size 9 sub { 
  5610.         /x exch def
  5611.         asp2 2 sub asp3 asp2 sub size 9 sub {
  5612.             /y exch def
  5613.             x y putalgnpat
  5614.         } for
  5615.     } for
  5616.     
  5617.     % Timing patterns
  5618.     format (full) eq {
  5619.         8 1 size 9 sub {
  5620.             /i exch def
  5621.             pixs i 6 qmv i 1 add 2 mod put
  5622.             pixs 6 i qmv i 1 add 2 mod put
  5623.         } for
  5624.     } {
  5625.         8 1 size 1 sub {
  5626.             /i exch def
  5627.             pixs i 0 qmv i 1 add 2 mod put
  5628.             pixs 0 i qmv i 1 add 2 mod put
  5629.         } for
  5630.     } ifelse
  5631.     
  5632.     % Format information modules
  5633.     format (full) eq {
  5634.         /formatmap [
  5635.             [ [ 0 8 ] [ 8 size 1 sub ] ]  [ [ 1 8 ] [ 8 size 2 sub ] ]  [ [ 2 8 ] [ 8 size 3 sub ] ]
  5636.             [ [ 3 8 ] [ 8 size 4 sub ] ]  [ [ 4 8 ] [ 8 size 5 sub ] ]  [ [ 5 8 ] [ 8 size 6 sub ] ]
  5637.             [ [ 7 8 ] [ 8 size 7 sub ] ]  [ [ 8 8 ] [ size 8 sub 8 ] ]  [ [ 8 7 ] [ size 7 sub 8 ] ]
  5638.             [ [ 8 5 ] [ size 6 sub 8 ] ]  [ [ 8 4 ] [ size 5 sub 8 ] ]  [ [ 8 3 ] [ size 4 sub 8 ] ]
  5639.             [ [ 8 2 ] [ size 3 sub 8 ] ]  [ [ 8 1 ] [ size 2 sub 8 ] ]  [ [ 8 0 ] [ size 1 sub 8 ] ]
  5640.         ] def
  5641.     } {
  5642.         /formatmap [
  5643.             [ [ 1 8 ] ]  [ [ 2 8 ] ]  [ [ 3 8 ] ]  [ [ 4 8 ] ]  [ [ 5 8 ] ]
  5644.             [ [ 6 8 ] ]  [ [ 7 8 ] ]  [ [ 8 8 ] ]  [ [ 8 7 ] ]  [ [ 8 6 ] ]
  5645.             [ [ 8 5 ] ]  [ [ 8 4 ] ]  [ [ 8 3 ] ]  [ [ 8 2 ] ]  [ [ 8 1 ] ]
  5646.         ] def
  5647.     } ifelse
  5648.     formatmap {
  5649.         { {} forall qmv pixs exch 0 put } forall
  5650.     } forall
  5651.     
  5652.     % Version information modules
  5653.     size 45 ge {
  5654.         /versionmap [
  5655.             [ [ size  9 sub 5 ] [ 5 size  9 sub ] ]  [ [ size 10 sub 5 ] [ 5 size 10 sub ] ]
  5656.             [ [ size 11 sub 5 ] [ 5 size 11 sub ] ]  [ [ size  9 sub 4 ] [ 4 size  9 sub ] ]
  5657.             [ [ size 10 sub 4 ] [ 4 size 10 sub ] ]  [ [ size 11 sub 4 ] [ 4 size 11 sub ] ]
  5658.             [ [ size  9 sub 3 ] [ 3 size  9 sub ] ]  [ [ size 10 sub 3 ] [ 3 size 10 sub ] ]
  5659.             [ [ size 11 sub 3 ] [ 3 size 11 sub ] ]  [ [ size  9 sub 2 ] [ 2 size  9 sub ] ]
  5660.             [ [ size 10 sub 2 ] [ 2 size 10 sub ] ]  [ [ size 11 sub 2 ] [ 2 size 11 sub ] ]
  5661.             [ [ size  9 sub 1 ] [ 1 size  9 sub ] ]  [ [ size 10 sub 1 ] [ 1 size 10 sub ] ]
  5662.             [ [ size 11 sub 1 ] [ 1 size 11 sub ] ]  [ [ size  9 sub 0 ] [ 0 size  9 sub ] ]
  5663.             [ [ size 10 sub 0 ] [ 0 size 10 sub ] ]  [ [ size 11 sub 0 ] [ 0 size 11 sub ] ]
  5664.         ] def
  5665.     } {
  5666.         /versionmap [] def
  5667.     } ifelse
  5668.     versionmap {
  5669.         { {} forall qmv pixs exch 0 put } forall
  5670.     } forall
  5671.     
  5672.     % Solitary dark module in full symbols
  5673.     format (full) eq {
  5674.         pixs 8 size 8 sub qmv 1 put
  5675.     } if
  5676.     
  5677.     % Calculate the mask patterns
  5678.     format (full) eq {
  5679.         /maskfuncs [ 
  5680.             {add 2 mod} bind
  5681.             {exch pop 2 mod} bind
  5682.             {pop 3 mod} bind
  5683.             {add 3 mod} bind
  5684.             {2 idiv exch 3 idiv add 2 mod} bind
  5685.             {mul dup 2 mod exch 3 mod add} bind
  5686.             {mul dup 2 mod exch 3 mod add 2 mod} bind
  5687.             {2 copy mul 3 mod 3 1 roll add 2 mod add 2 mod} bind
  5688.         ] def
  5689.     } {
  5690.         /maskfuncs [ 
  5691.             {exch pop 2 mod} bind
  5692.             {2 idiv exch 3 idiv add 2 mod} bind
  5693.             {mul dup 2 mod exch 3 mod add 2 mod} bind
  5694.             {2 copy mul 3 mod 3 1 roll add 2 mod add 2 mod} bind
  5695.         ] def
  5696.     } ifelse
  5697.     /masks maskfuncs length array def
  5698.     0 1 masks length 1 sub {
  5699.         /m exch def
  5700.         /mask size size mul array def
  5701.         0 1 size 1 sub {
  5702.             /j exch def
  5703.             0 1 size 1 sub {
  5704.                 /i exch def
  5705.                 i j maskfuncs m get exec 0 eq 
  5706.                 pixs i j qmv get -1 eq and {1} {0} ifelse
  5707.                 mask i j qmv 3 -1 roll put
  5708.             } for
  5709.         } for
  5710.         masks m mask put
  5711.     } for
  5712.     
  5713.     % Walk the symbol placing the bitstream
  5714.     /posx size 1 sub def
  5715.     /posy size 1 sub def
  5716.     /dir -1 def  % -1 is upwards, 1 is downwards
  5717.     /col 1 def   % 0 is left bit, 1 is right bit
  5718.     /num 0 def
  5719.     { % loop
  5720.         posx 0 lt {exit} if
  5721.         pixs posx posy qmv get -1 eq {
  5722.             cws num 8 idiv get 7 num 8 mod sub neg bitshift 1 and
  5723.             pixs posx posy qmv 3 -1 roll put
  5724.             /num num 1 add def
  5725.         } if
  5726.         col 1 eq {
  5727.             /col 0 def
  5728.             /posx posx 1 sub def
  5729.         } {
  5730.             /col 1 def
  5731.             /posx posx 1 add def 
  5732.             /posy posy dir add def
  5733.             posy 0 lt posy size ge or {  % Turn around at top and bottom
  5734.                 /dir dir -1 mul def
  5735.                 /posy posy dir add def
  5736.                 /posx posx 2 sub def
  5737.                 % Hop over the timing pattern in full size symbols
  5738.                 format (full) eq posx 6 eq and {/posx posx 1 sub def} if
  5739.             } if
  5740.         } ifelse
  5741.     } loop
  5742.  
  5743.     % Evaluate runlength encoded rows or columns in full symbols
  5744.     /evalfulln1n3 {
  5745.         /scrle exch def
  5746.         % Detect runs of 5 or more like modules
  5747.         /scr1 0 scrle { dup 5 ge {add 2 sub dup} if pop } forall def
  5748.         % Detect 1:1:3:1:1 ratio next to 4 modules of whitespace
  5749.         /scr3 0 def
  5750.         3 2 scrle length 3 sub {  % Scan odd (dark) runs within bounds
  5751.             /j exch def
  5752.             scrle j get 3 mod 0 eq {  % Multiple of 3 black modules
  5753.                 /fact scrle j get 3 idiv def
  5754.                 scrle j 2 sub 5 getinterval {fact eq} forall and exch pop and and {
  5755.                     j 3 eq j 4 add scrle length ge or {  % At either extent of run
  5756.                         /scr3 scr3 40 add def
  5757.                     } {  % Bounded by dark modules
  5758.                         scrle j 3 sub get 4 ge scrle j 3 add get 4 ge or {
  5759.                             /scr3 scr3 40 add def
  5760.                         } if
  5761.                     } ifelse
  5762.                 } if
  5763.             } if
  5764.         } for
  5765.         scr1 scr3
  5766.     } bind def
  5767.     
  5768.     % Evaluation algorithm for full symbols
  5769.     /evalfull {
  5770.         /sym exch def
  5771.  
  5772.         /n1 0 def /n2 0 def /n3 0 def
  5773.         /rle size array def
  5774.         /lastpairs size array def
  5775.         /thispairs size array def
  5776.         /sizeadd1 size 1 add def
  5777.         0 1 size 1 sub {  
  5778.             /i exch def
  5779.  
  5780.             % Runlength encode (light, dark, light, ...) and evaluate each column
  5781.             mark 0 0
  5782.             i size dup dup mul 1 sub {
  5783.                 sym exch get exch 1 index eq {exch 1 add exch} {1 exch} ifelse
  5784.             } for
  5785.             pop
  5786.             rle 0 counttomark 2 sub getinterval astore
  5787.             evalfulln1n3 n3 add /n3 exch def n1 add /n1 exch def
  5788.             pop
  5789.  
  5790.             % Runlength encode (light, dark, light, ...) and evaluate each row
  5791.             /symrow sym i size mul size getinterval def
  5792.             mark 0 0 
  5793.             symrow { 
  5794.                 exch 1 index eq {exch 1 add exch} {1 exch} ifelse
  5795.             } forall 
  5796.             pop
  5797.             rle 0 counttomark 2 sub getinterval astore
  5798.             evalfulln1n3 n3 add /n3 exch def n1 add /n1 exch def
  5799.             pop
  5800.  
  5801.             % Count and score same coloured blocks
  5802.             /lastpairs thispairs /thispairs lastpairs def def
  5803.             symrow 0 get 1 eq {0} {1} ifelse
  5804.             symrow {exch 1 index add exch} forall
  5805.             pop
  5806.             thispairs astore pop
  5807.             i 0 gt {
  5808.                 mark
  5809.                 lastpairs aload pop thispairs aload pop
  5810.                 n2 size { exch sizeadd1 index add 3 and 0 eq {3 add} if } repeat
  5811.                 /n2 exch def
  5812.                 cleartomark
  5813.             } if
  5814.  
  5815.         } for
  5816.  
  5817.         % Score dark/light imbalance 
  5818.         /dark 0 sym {add} forall def
  5819.         /n4 dark 100 mul size dup mul div 50 sub abs 5 div cvi 10 mul def
  5820.  
  5821.         n1 n2 add n3 add n4 add
  5822.     } bind def
  5823.  
  5824.     % Evaluation algorithm for micro symbols
  5825.     /evalmicro {
  5826.         /sym exch def
  5827.         /dkrhs 0 def /dkbot 0 def
  5828.         1 1 size 1 sub {
  5829.             /i exch def
  5830.             /dkrhs dkrhs sym size 1 sub i qmv get add def
  5831.             /dkbot dkbot sym i size 1 sub qmv get add def
  5832.         } for
  5833.         dkrhs dkbot le {
  5834.             dkrhs 16 mul dkbot add neg
  5835.         } {
  5836.             dkbot 16 mul dkrhs add neg
  5837.         } ifelse
  5838.     } bind def
  5839.     
  5840.     % Evaluate the masked symbols to find the most suitable
  5841.     /bestscore 999999999 def
  5842.     0 1 masks length 1 sub {
  5843.         /m exch def
  5844.         /masksym size size mul array def
  5845.         0 1 size size mul 1 sub {
  5846.             /i exch def
  5847.             masksym i pixs i get masks m get i get xor put
  5848.         } for
  5849.         format (full) eq {
  5850.             masksym evalfull /score exch def
  5851.         } {
  5852.             masksym evalmicro /score exch def
  5853.         } ifelse
  5854.         score bestscore lt { 
  5855.             /bestsym masksym def
  5856.             /bestmaskval m def
  5857.             /bestscore score def
  5858.         } if    
  5859.     } for
  5860.     /pixs bestsym def
  5861.     
  5862.     % Add the format information
  5863.     format (full) eq {
  5864.         /fmtvals [
  5865.             16#5412 16#5125 16#5e7c 16#5b4b 16#45f9 16#40ce 16#4f97 16#4aa0 
  5866.             16#77c4 16#72f3 16#7daa 16#789d 16#662f 16#6318 16#6c41 16#6976
  5867.             16#1689 16#13be 16#1ce7 16#19d0 16#0762 16#0255 16#0d0c 16#083b 
  5868.             16#355f 16#3068 16#3f31 16#3a06 16#24b4 16#2183 16#2eda 16#2bed
  5869.         ] def
  5870.         /ecid (MLHQ) eclevel search pop length exch pop exch pop def
  5871.         /fmtval fmtvals ecid 3 bitshift bestmaskval add get def
  5872.     } {
  5873.         /fmtvals [
  5874.             16#4445 16#4172 16#4e2b 16#4b1c 16#55ae 16#5099 16#5fc0 16#5af7
  5875.             16#6793 16#62a4 16#6dfd 16#68ca 16#7678 16#734f 16#7c16 16#7921
  5876.             16#06de 16#03e9 16#0cb0 16#0987 16#1735 16#1202 16#1d5b 16#186c
  5877.             16#2508 16#203f 16#2f66 16#2a51 16#34e3 16#31d4 16#3e8d 16#3bba
  5878.         ] def
  5879.         /symid [ [0] [1 2] [3 4] [5 6 7] ] size 11 sub 2 idiv get eclval get def
  5880.         /fmtval fmtvals symid 2 bitshift bestmaskval add get def
  5881.     } ifelse
  5882.     0 1 formatmap length 1 sub {
  5883.         /i exch def
  5884.         formatmap i get {
  5885.             pixs exch {} forall qmv fmtval 14 i sub neg bitshift 1 and put
  5886.         } forall
  5887.     } for
  5888.     
  5889.     % Add the version information
  5890.     size 45 ge {
  5891.         /vervals [
  5892.             16#07c94 16#085bc 16#09a99 16#0a4d3 16#0bbf6 16#0c762 16#0d847 
  5893.             16#0e60d 16#0f928 16#10b78 16#1145d 16#12a17 16#13532 16#149a6 
  5894.             16#15683 16#168c9 16#177ec 16#18ec4 16#191e1 16#1afab 16#1b08e 
  5895.             16#1cc1a 16#1d33f 16#1ed75 16#1f250 16#209d5 16#216fd 16#228ba 
  5896.             16#2379f 16#24b0b 16#2542e 16#26a64 16#27541 16#28c69
  5897.         ] def
  5898.         /verval vervals size 17 sub 4 idiv 7 sub get def
  5899.         0 1 versionmap length 1 sub {
  5900.             /i exch def
  5901.             versionmap i get {
  5902.                 pixs exch {} forall qmv verval 17 i sub neg bitshift 1 and put
  5903.             } forall
  5904.         } for
  5905.     } if
  5906.  
  5907.     % Return the arguments
  5908.     <<
  5909.     /ren (renmatrix)
  5910.     /pixs pixs
  5911.     /pixx size
  5912.     /pixy size
  5913.     /height size 2 mul 72 div
  5914.     /width size 2 mul 72 div
  5915.     /opt options
  5916.     >>
  5917.  
  5918.     dontdraw not {//renmatrix exec} if
  5919.  
  5920.     end
  5921.  
  5922. } bind def
  5923. % --END ENCODER qrcode--
  5924.  
  5925. % --BEGIN ENCODER maxicode--
  5926. % --DESC: MaxiCode
  5927. % --EXAM: ^059^042^041^059^040^03001^02996152382802^029840^029001^0291Z00004951^029UPSN^02906X610^029159^0291234567^0291^0471^029^029Y^029634 ALPHA DR^029PITTSBURGH^029PA^030^062^004^063
  5928. % --EXOP: mode=2
  5929. % --RNDR: renmaximatrix
  5930. /maxicode {
  5931.  
  5932.     1 dict begin
  5933.  
  5934.     /options exch def        % We are given an option string
  5935.     /barcode exch def        % We are given a barcode string
  5936.  
  5937.     /dontdraw false def
  5938.     /mode 4 def
  5939.     /sam -1 def
  5940.  
  5941.     % Parse the input options
  5942.     options type /stringtype eq {
  5943.         1 dict begin
  5944.         options {
  5945.             token false eq {exit} if dup length string cvs (=) search
  5946.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  5947.         } loop
  5948.         currentdict end /options exch def
  5949.     } if
  5950.     options {def} forall
  5951.  
  5952.     /mode mode cvi def
  5953.     /sam sam cvi def
  5954.  
  5955.     /txtvals (@ABCDEFGHIJKLMNOPQRSTUVWXYZ@@@@@ @@@@@@@@@@@@@@@0123456789@@@@@@) def
  5956.  
  5957.     % Parse a given message into codewords
  5958.     /maxiparse {
  5959.         /txt exch def
  5960.         /out txt length array def
  5961.         /i 0 def /j 0 def
  5962.         { % loop  
  5963.             i txt length eq {exit} if
  5964.             txt i 1 getinterval (^) eq {
  5965.                 % Codeword is given by the next three characters
  5966.                 /cw txt i 1 add 3 getinterval cvi def
  5967.                 /i i 4 add def
  5968.             } {
  5969.                 % Codeword is the characters position in txtvals
  5970.                 txtvals txt i 1 getinterval search 
  5971.                 pop length /cw exch def pop pop
  5972.                 /i i 1 add def
  5973.             } ifelse
  5974.             out j cw put
  5975.             /j j 1 add def 
  5976.         } loop
  5977.         out 0 j getinterval
  5978.     } bind def
  5979.  
  5980.     % Calcalate the structured append mode insert
  5981.     /sami () def
  5982.     sam -1 ne {
  5983.         /sami (^033^000) 8 string copy def
  5984.         sam 10 idiv 1 sub 8 mul sam 10 mod 1 sub add 10 2 string cvrs
  5985.         dup length 8 exch sub sami exch 3 -1 roll putinterval 
  5986.     } if
  5987.  
  5988.     % Message handling for modes 2 and 3
  5989.     mode 2 eq mode 3 eq or {
  5990.  
  5991.         /msg barcode def
  5992.  
  5993.         % Normalise messages that begin with a field identifier [)>RS01GSyy
  5994.         msg (^059^042^041^059^040^03001^029) search {
  5995.             pop
  5996.             dup length 2 add string /fid exch def
  5997.             fid 0 3 -1 roll putinterval
  5998.             dup fid fid length 2 sub 3 -1 roll 0 2 getinterval putinterval
  5999.             dup length 2 sub 2 exch getinterval /msg exch def
  6000.         } {
  6001.             pop
  6002.             /fid () def
  6003.         } ifelse
  6004.  
  6005.         % Read the postcode, country code and service code fields
  6006.         msg (^029) search pop /pc exch def
  6007.         pop (^029) search pop /cc exch def
  6008.         pop (^029) search pop /sc exch def
  6009.         pop /msg exch def
  6010.  
  6011.         % Calculate the fixed-width binary values for the mode, postcode, country code and service
  6012.         /mdb (0000) 4 string copy dup mode cvi 2 4 string cvrs dup length 4 exch sub exch putinterval def
  6013.         /ccb (0000000000) 10 string copy dup cc cvi 2 10 string cvrs dup length 10 exch sub exch putinterval def
  6014.         /scb (0000000000) 10 string copy dup sc cvi 2 10 string cvrs dup length 10 exch sub exch putinterval def
  6015.         /pcb (000000000000000000000000000000000000) 36 string copy def
  6016.         mode 2 eq {
  6017.             % For numeric postcode, first six bits represent length and remaining 30 bits the value
  6018.             pcb pc length 2 6 string cvrs dup length 6 exch sub exch putinterval
  6019.             pcb pc cvi 2 30 string cvrs dup length 36 exch sub exch putinterval
  6020.         } {  % mode=3
  6021.             % For alphanumeric postcode, trim or pad with spaces to 6 chars and encode to binary
  6022.             /pccw (      ) 6 string copy dup 0 pc length 6 gt {pc 0 6 getinterval} {pc} ifelse putinterval maxiparse def
  6023.             0 1 5 {
  6024.                 /i exch def
  6025.                 pcb pccw i get 2 6 string cvrs dup length 6 i mul 6 add exch sub exch putinterval
  6026.             } for
  6027.         } ifelse
  6028.  
  6029.         % Convolute the binary values into the structured carrier message
  6030.         /scm 60 string def
  6031.         scm 2  mdb putinterval
  6032.         scm 38 pcb 0  4 getinterval putinterval
  6033.         scm 30 pcb 4  6 getinterval putinterval
  6034.         scm 24 pcb 10 6 getinterval putinterval
  6035.         scm 18 pcb 16 6 getinterval putinterval
  6036.         scm 12 pcb 22 6 getinterval putinterval
  6037.         scm 6  pcb 28 6 getinterval putinterval
  6038.         scm 0  pcb 34 2 getinterval putinterval
  6039.         scm 52 ccb 0  2 getinterval putinterval
  6040.         scm 42 ccb 2  6 getinterval putinterval
  6041.         scm 36 ccb 8  2 getinterval putinterval
  6042.         scm 54 scb 0  6 getinterval putinterval
  6043.         scm 48 scb 6  4 getinterval putinterval
  6044.  
  6045.         % Evaluate the structured carrier message as codewords
  6046.         /pri [ 0 0 0 0 0 0 0 0 0 0 ] def
  6047.         0 1 59 { 
  6048.             /i exch def
  6049.             /ps i 6 idiv def
  6050.             /ep 2 5 i 6 mod sub exp cvi scm i get 48 sub mul def
  6051.             pri ps pri ps get ep add put
  6052.         } for
  6053.  
  6054.         % Encode the secondary parts, including any SAM insert and field identifier
  6055.         /sec [ 84 {33} repeat ] def
  6056.         sec 0 [ sami maxiparse {} forall fid maxiparse {} forall msg maxiparse {} forall ] putinterval
  6057.  
  6058.     } if
  6059.  
  6060.     % Message handling for modes 4, 5 and 6
  6061.     mode 4 eq mode 5 eq or mode 6 eq or {
  6062.  
  6063.         % Prefix the message with the structured append insert
  6064.         /msg sami length barcode length add string def
  6065.         msg 0 sami putinterval
  6066.         msg sami length barcode putinterval
  6067.  
  6068.         % First symbol is the mode and the remainder are the padded message
  6069.         /cws [ mode 5 eq {78} {94} ifelse {33} repeat ] def
  6070.         cws 0 mode put
  6071.         cws 1 msg maxiparse putinterval
  6072.  
  6073.         % Fit the message into the primary and secondary components
  6074.         /pri cws 0 10 getinterval def
  6075.         /sec cws 10 cws length 10 sub getinterval def
  6076.  
  6077.     } if
  6078.  
  6079.     % Create the 64x64 Reed-Solomon table
  6080.     /rstable 64 64 mul array def
  6081.     rstable 0 [ 64 {0} repeat ] putinterval
  6082.     rstable 64 [ 0 1 63 {} for ] putinterval
  6083.     /prev 1 def
  6084.     64 {       
  6085.         /next prev 1 bitshift def
  6086.         next 64 and 0 ne {
  6087.             /next next 67 xor def
  6088.         } if        
  6089.         0 1 63 {
  6090.             /j exch def
  6091.             /nextcell {rstable 64 next mul j add} def
  6092.             nextcell rstable 64 prev mul j add get 1 bitshift put
  6093.             nextcell get 64 and 0 ne {
  6094.                 nextcell nextcell get 67 xor put
  6095.             } if
  6096.         } for
  6097.         /prev next def
  6098.     } repeat
  6099.  
  6100.     % Calculate the parity codewords for primary codewords 
  6101.     /pgen [46 44 49 3 2 57 42 39 28 31 1] def
  6102.     /rscodes [ 10 {0} repeat 9 -1 0 { pri exch get } for ] def
  6103.     rscodes length 11 sub -1 0 {
  6104.         /i exch def
  6105.         0 1 10 {
  6106.             /j exch def
  6107.             rscodes i j add rscodes i j add get
  6108.             rstable 64 pgen j get mul rscodes i 10 add get add get
  6109.             xor put
  6110.         } for
  6111.     } for
  6112.     /prichk [ 9 -1 0 { rscodes exch get } for ] def
  6113.  
  6114.     % Split secondary codeword into odd and even elements
  6115.     /seco [ 0 2 sec length 1 sub { sec exch get } for ] def
  6116.     /sece [ 1 2 sec length 1 sub { sec exch get } for ] def
  6117.  
  6118.     % Calculate the parity codewords for secondary codeword parts based on mode
  6119.     sec length 84 eq {  % SEC mode
  6120.         /sgen [ 59 23 19 31 33 38 17 22 48 15 36 57 37 22 8 27 33 11 44 23 1 ] def
  6121.     } {  % EEC mode
  6122.         /sgen [ 28 11 20 7 43 9 41 34 49 46 37 40 55 34 45 61 13 23 29 22 10 35 55 41 10 53 45 22 1 ] def
  6123.     } ifelse
  6124.     /scodes sgen length 1 sub def
  6125.     /rscodes [ scodes {0} repeat seco length 1 sub -1 0 { seco exch get } for ] def
  6126.     rscodes length scodes sub 1 sub -1 0 {
  6127.         /i exch def
  6128.         0 1 scodes {
  6129.             /j exch def
  6130.             rscodes i j add rscodes i j add get
  6131.             rstable 64 sgen j get mul rscodes i scodes add get add get
  6132.             xor put
  6133.         } for
  6134.     } for
  6135.     /secochk [ scodes 1 sub -1 0 { rscodes exch get } for ] def
  6136.     /rscodes [ scodes {0} repeat sece length 1 sub -1 0 { sece exch get } for ] def
  6137.     rscodes length scodes sub 1 sub -1 0 {
  6138.         /i exch def
  6139.         0 1 scodes {
  6140.             /j exch def
  6141.             rscodes i j add rscodes i j add get
  6142.             rstable 64 sgen j get mul rscodes i scodes add get add get
  6143.             xor put
  6144.         } for
  6145.     } for
  6146.     /secechk [ scodes 1 sub -1 0 { rscodes exch get } for ] def
  6147.  
  6148.     % Recompose the secondary parity codewords
  6149.     /secchk [ 0 1 scodes 1 sub { dup secochk exch get exch secechk exch get } for ] def
  6150.  
  6151.     % Concatinate the data into final codewords
  6152.     /codewords [
  6153.         pri {} forall 
  6154.         prichk {} forall
  6155.         sec {} forall 
  6156.         secchk {} forall
  6157.     ] def
  6158.  
  6159.     % Convert the codewords into module bits
  6160.     /mods [ 864 {0} repeat ] def
  6161.     0 1 143 {
  6162.         /i exch def
  6163.         /cw [ codewords i get 2 6 string cvrs {48 sub} forall ] def
  6164.         mods 6 i mul 6 cw length sub add cw putinterval
  6165.     } for
  6166.  
  6167.     % Maps modules to pixels in the grid
  6168.     /modmap [
  6169.         469 529 286 316 347 346 673 672 703 702 647 676 283 282 313 312 370 610 618 379 
  6170.         378 409 408 439 705 704 559 589 588 619 458 518 640 701 675 674 285 284 315 314 
  6171.         310 340 531 289 288 319 349 348 456 486 517 516 471 470 369 368 399 398 429 428 
  6172.         549 548 579 578 609 608 649 648 679 678 709 708 639 638 669 668 699 698 279 278 
  6173.         309 308 339 338 381 380 411 410 441 440 561 560 591 590 621 620 547 546 577 576 
  6174.         607 606 367 366 397 396 427 426 291 290 321 320 351 350 651 650 681 680 711 710 
  6175.         1   0   31  30  61  60  3   2   33  32  63  62  5   4   35  34  65  64  7   6   
  6176.         37  36  67  66  9   8   39  38  69  68  11  10  41  40  71  70  13  12  43  42  
  6177.         73  72  15  14  45  44  75  74  17  16  47  46  77  76  19  18  49  48  79  78  
  6178.         21  20  51  50  81  80  23  22  53  52  83  82  25  24  55  54  85  84  27  26  
  6179.         57  56  87  86  117 116 147 146 177 176 115 114 145 144 175 174 113 112 143 142 
  6180.         173 172 111 110 141 140 171 170 109 108 139 138 169 168 107 106 137 136 167 166 
  6181.         105 104 135 134 165 164 103 102 133 132 163 162 101 100 131 130 161 160 99  98  
  6182.         129 128 159 158 97  96  127 126 157 156 95  94  125 124 155 154 93  92  123 122 
  6183.         153 152 91  90  121 120 151 150 181 180 211 210 241 240 183 182 213 212 243 242 
  6184.         185 184 215 214 245 244 187 186 217 216 247 246 189 188 219 218 249 248 191 190 
  6185.         221 220 251 250 193 192 223 222 253 252 195 194 225 224 255 254 197 196 227 226 
  6186.         257 256 199 198 229 228 259 258 201 200 231 230 261 260 203 202 233 232 263 262 
  6187.         205 204 235 234 265 264 207 206 237 236 267 266 297 296 327 326 357 356 295 294 
  6188.         325 324 355 354 293 292 323 322 353 352 277 276 307 306 337 336 275 274 305 304 
  6189.         335 334 273 272 303 302 333 332 271 270 301 300 331 330 361 360 391 390 421 420 
  6190.         363 362 393 392 423 422 365 364 395 394 425 424 383 382 413 412 443 442 385 384 
  6191.         415 414 445 444 387 386 417 416 447 446 477 476 507 506 537 536 475 474 505 504 
  6192.         535 534 473 472 503 502 533 532 455 454 485 484 515 514 453 452 483 482 513 512 
  6193.         451 450 481 480 511 510 541 540 571 570 601 600 543 542 573 572 603 602 545 544 
  6194.         575 574 605 604 563 562 593 592 623 622 565 564 595 594 625 624 567 566 597 596 
  6195.         627 626 657 656 687 686 717 716 655 654 685 684 715 714 653 652 683 682 713 712 
  6196.         637 636 667 666 697 696 635 634 665 664 695 694 633 632 663 662 693 692 631 630 
  6197.         661 660 691 690 721 720 751 750 781 780 723 722 753 752 783 782 725 724 755 754 
  6198.         785 784 727 726 757 756 787 786 729 728 759 758 789 788 731 730 761 760 791 790 
  6199.         733 732 763 762 793 792 735 734 765 764 795 794 737 736 767 766 797 796 739 738 
  6200.         769 768 799 798 741 740 771 770 801 800 743 742 773 772 803 802 745 744 775 774 
  6201.         805 804 747 746 777 776 807 806 837 836 867 866 897 896 835 834 865 864 895 894 
  6202.         833 832 863 862 893 892 831 830 861 860 891 890 829 828 859 858 889 888 827 826 
  6203.         857 856 887 886 825 824 855 854 885 884 823 822 853 852 883 882 821 820 851 850 
  6204.         881 880 819 818 849 848 879 878 817 816 847 846 877 876 815 814 845 844 875 874 
  6205.         813 812 843 842 873 872 811 810 841 840 871 870 901 900 931 930 961 960 903 902 
  6206.         933 932 963 962 905 904 935 934 965 964 907 906 937 936 967 966 909 908 939 938 
  6207.         969 968 911 910 941 940 971 970 913 912 943 942 973 972 915 914 945 944 975 974 
  6208.         917 916 947 946 977 976 919 918 949 948 979 978 921 920 951 950 981 980 923 922 
  6209.         953 952 983 982 925 924 955 954 985 984 927 926 957 956 987 986 58  89  88  118 
  6210.         149 148 178 209 208 238 269 268 298 329 328 358 389 388 418 449 448 478 509 508 
  6211.         538 569 568 598 629 628 658 689 688 718 749 748 778 809 808 838 869 868 898 929 
  6212.         928 958 989 988
  6213.     ] def
  6214.  
  6215.     % Lookup pixels for enabled modules from modmap
  6216.     /pixs 864 array def
  6217.     /j 0 def
  6218.     0 1 mods length 1 sub {
  6219.         /i exch def
  6220.         mods i get 1 eq {
  6221.             pixs j modmap i get put
  6222.             /j j 1 add def
  6223.         } if
  6224.     } for
  6225.     /pixs [ pixs 0 j getinterval {} forall 28 29 280 281 311 457 488 500 530 670 700 677 707 ] def
  6226.  
  6227.     % Return the arguments
  6228.     <<
  6229.     /ren (renmaximatrix)
  6230.     /pixs pixs
  6231.     /opt options
  6232.     >>
  6233.  
  6234.     dontdraw not {//renmaximatrix exec} if
  6235.  
  6236.     end
  6237.  
  6238. } bind def
  6239. % --END ENCODER maxicode--
  6240.  
  6241. % --BEGIN ENCODER azteccode--
  6242. % --DESC: Aztec Code
  6243. % --EXAM: 00100111001000000101001101111000010100111100101000000110
  6244. % --EXOP: format=compact
  6245. % --RNDR: renmatrix
  6246. /azteccode {
  6247.  
  6248.     1 dict begin
  6249.  
  6250.     /options exch def
  6251.     /barcode exch def
  6252.  
  6253.     /dontdraw false def
  6254.     /format (unset) def    % full, compact or rune
  6255.     /readerinit false def
  6256.     /layers -1 def
  6257.     /eclevel 23 def
  6258.     /ecaddchars 3 def
  6259.  
  6260.     % Parse the input options
  6261.     options type /stringtype eq {
  6262.         1 dict begin
  6263.         options {
  6264.             token false eq {exit} if dup length string cvs (=) search
  6265.             true eq {cvlit exch pop exch def} {cvlit true def} ifelse
  6266.         } loop
  6267.         currentdict end /options exch def
  6268.     } if
  6269.     options {def} forall
  6270.  
  6271.     /layers layers cvi def
  6272.     /eclevel eclevel cvr def
  6273.     /ecaddchars ecaddchars cvi def
  6274.     
  6275.     % Convert from input into message bitstream
  6276.     /msgbits () def 
  6277.     format (rune) ne {/msgbits barcode def} if 
  6278.    
  6279.     % Lookup the most appropriate symbol specification 
  6280.     /metrics [
  6281.         [ (rune)     0 0    0  6 ]  % Special metric for rune symbols
  6282.         [ (compact)  1 1   17  6 ] [ (full)     1 1   21  6 ] [ (compact)  2 0   40  6 ]
  6283.         [ (full)     2 1   48  6 ] [ (compact)  3 0   51  8 ] [ (full)     3 1   60  8 ]
  6284.         [ (compact)  4 0   76  8 ] [ (full)     4 1   88  8 ] [ (full)     5 1  120  8 ]
  6285.         [ (full)     6 1  156  8 ] [ (full)     7 1  196  8 ] [ (full)     8 1  240  8 ]
  6286.         [ (full)     9 1  230 10 ] [ (full)    10 1  272 10 ] [ (full)    11 1  316 10 ]
  6287.         [ (full)    12 1  364 10 ] [ (full)    13 1  416 10 ] [ (full)    14 1  470 10 ]
  6288.         [ (full)    15 1  528 10 ] [ (full)    16 1  588 10 ] [ (full)    17 1  652 10 ]
  6289.         [ (full)    18 1  720 10 ] [ (full)    19 1  790 10 ] [ (full)    20 1  864 10 ]
  6290.         [ (full)    21 1  940 10 ] [ (full)    22 1 1020 10 ] [ (full)    23 0  920 12 ]
  6291.         [ (full)    24 0  992 12 ] [ (full)    25 0 1066 12 ] [ (full)    26 0 1144 12 ]
  6292.         [ (full)    27 0 1224 12 ] [ (full)    28 0 1306 12 ] [ (full)    29 0 1392 12 ]
  6293.         [ (full)    30 0 1480 12 ] [ (full)    31 0 1570 12 ] [ (full)    32 0 1664 12 ]
  6294.     ] def
  6295.  
  6296.     /i 0 def
  6297.     { % loop
  6298.         /m metrics i get def
  6299.         /frmt m 0 get def                          % Format of the symbol
  6300.         /mlyr m 1 get def                          % Data layers
  6301.         /icap m 2 get def                          % Reader initialisation capable
  6302.         /ncws m 3 get def                          % Total of codewords
  6303.         /bpcw m 4 get def                          % Bits per codeword
  6304.         /numecw ncws eclevel mul 100 div ecaddchars add ceiling cvi def
  6305.         msgbits length 0 eq {/numecw 0 def} if     % Error correction codewords 
  6306.         /numdcw ncws numecw sub def                % Data codewords
  6307.         /okay true def
  6308.         format (unset) ne format frmt ne and {/okay false def} if
  6309.         readerinit icap 1 ne and {/okay false def} if
  6310.         layers -1 ne layers mlyr ne and {/okay false def} if 
  6311.         msgbits length bpcw div ceiling cvi numdcw gt {/okay false def} if
  6312.         okay {exit} if
  6313.         /i i 1 add def
  6314.     } loop
  6315.     /layers mlyr def
  6316.     /format frmt def
  6317.  
  6318.     % Expand message bits into codewords avoiding codewords with all zeros or all ones
  6319.     /allzero {dup length (000000000000) 0 3 -1 roll getinterval eq} bind def
  6320.     /allones {dup length (111111111111) 0 3 -1 roll getinterval eq} bind def
  6321.     /cws ncws array def
  6322.     /m 0 def /c 0 def
  6323.     {
  6324.         msgbits length m le {exit} if
  6325.         msgbits length m sub bpcw ge {
  6326.             /cwb msgbits m bpcw 1 sub getinterval def        % All but last bit
  6327.             /cwf msgbits m bpcw add 1 sub 1 getinterval def  % Last bit
  6328.             cwb allzero {/cwf (1) def /m m 1 sub def} if     % Flip last bit to avoid zeros
  6329.             cwb allones {/cwf (0) def /m m 1 sub def} if     % Flip last bit to avoid ones
  6330.             % Concatinate the bits 
  6331.             12 string dup 0 cwb putinterval 
  6332.             dup bpcw 1 sub cwf putinterval
  6333.             0 bpcw getinterval
  6334.             /cwb exch def
  6335.         } {  %  Final codeword
  6336.             /cwb msgbits m msgbits length m sub getinterval def
  6337.             /cwb (111111111111) 12 string copy dup 0 cwb putinterval 0 bpcw getinterval def
  6338.             cwb allones {cwb cwb length 1 sub (0) putinterval} if  % Prevent all ones
  6339.         } ifelse
  6340.         % Conversion of binary data into byte array
  6341.         /cw 0 def
  6342.         0 1 bpcw 1 sub {
  6343.             /i exch def
  6344.             /cw cw 2 bpcw i sub 1 sub exp cvi cwb i get 48 sub mul add def
  6345.         } for
  6346.         cws c cw put
  6347.         /m m bpcw add def 
  6348.         /c c 1 add def
  6349.     } loop    
  6350.     /cws cws 0 c getinterval def
  6351.  
  6352.     % Reed-Solomon algorithm
  6353.     /rscodes {
  6354.  
  6355.         /rspm exch def
  6356.         /rsgf exch def
  6357.         /rsnc exch def
  6358.         /rscws exch def
  6359.  
  6360.         % Calculate the log and anti-log tables
  6361.         /rsalog [ 1 rsgf 1 sub { dup 2 mul dup rsgf ge {rspm xor} if } repeat ] def
  6362.         /rslog rsgf array def
  6363.         1 1 rsgf 1 sub {dup rsalog exch get exch rslog 3 1 roll put} for
  6364.  
  6365.         % Function to calculate the product in the field
  6366.         /rsprod {
  6367.             2 copy 0 ne exch 0 ne and {
  6368.                 rslog exch get exch rslog exch get add rsgf 1 sub mod rsalog exch get
  6369.             } {
  6370.                 pop pop 0
  6371.             } ifelse
  6372.         } bind def
  6373.  
  6374.         % Generate the coefficients
  6375.         /coeffs [ 1 rsnc {0} repeat ] def
  6376.         1 1 rsnc {
  6377.             /i exch def 
  6378.             coeffs i coeffs i 1 sub get put
  6379.             i 1 sub -1 1 {
  6380.                 /j exch def
  6381.                 coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put
  6382.             } for 
  6383.             coeffs 0 coeffs 0 get rsalog i get rsprod put
  6384.         } for
  6385.  
  6386.         % Extend the input with the error correction values
  6387.         /nd rscws length def
  6388.         /rscws [ rscws {} forall rsnc {0} repeat 0 ] def
  6389.         0 1 nd 1 sub {
  6390.             /k exch rscws exch get rscws nd get xor def 
  6391.             0 1 rsnc 1 sub {
  6392.                 /j exch def 
  6393.                 rscws nd j add rscws nd j add 1 add get k coeffs rsnc j sub 1 sub get rsprod xor put
  6394.             } for 
  6395.         } for
  6396.  
  6397.         % Return all but the last codeword
  6398.         rscws 0 rscws length 1 sub getinterval
  6399.  
  6400.     } bind def
  6401.  
  6402.     % Create the codewords and bit string for the mode
  6403.     format (full) eq {
  6404.         /mode layers 1 sub 11 bitshift cws length 1 sub add def
  6405.         readerinit {/mode mode 2#1000000000000000 or def} if
  6406.         /mode [
  6407.             mode 2#1111000000000000 and -12 bitshift
  6408.             mode 2#0000111100000000 and -8 bitshift
  6409.             mode 2#0000000011110000 and -4 bitshift
  6410.             mode 2#0000000000001111 and
  6411.         ] def
  6412.         /mode mode 6 16 19 rscodes def 
  6413.     } if
  6414.     format (compact) eq {
  6415.         /mode layers 1 sub 6 bitshift cws length 1 sub add def
  6416.         readerinit {/mode mode 2#10000000 or def} if 
  6417.         /mode [
  6418.             mode 2#11110000 and -4 bitshift
  6419.             mode 2#00001111 and
  6420.         ] def
  6421.         /mode mode 5 16 19 rscodes def
  6422.     } if
  6423.     format (rune) eq {
  6424.         /mode barcode cvi def
  6425.         /mode [
  6426.             mode 2#11110000 and -4 bitshift
  6427.             mode 2#00001111 and
  6428.         ] def
  6429.         /mode mode 5 16 19 rscodes def
  6430.         /mode [mode {2#1010 xor} forall] def  % Invert alternate bits
  6431.     } if
  6432.     /modebits mode length 4 mul string def
  6433.     0 1 modebits length 1 sub {modebits exch (0) putinterval} for
  6434.     0 1 mode length 1 sub {
  6435.         /i exch def
  6436.         modebits mode i get 2 4 string cvrs dup length 4 exch sub 4 i mul add exch putinterval 
  6437.     } for
  6438.  
  6439.     % Extend the data codewords with error correction codewords to create the bit string for the data
  6440.     /rsparams [
  6441.         [] [] [] [] [] [] 
  6442.         [ 64 67 ]      % 6-bit codewords 
  6443.         []
  6444.         [ 256 301 ]    % 8-bit codewords
  6445.         [] 
  6446.         [ 1024 1033 ]  % 10-bit codewords
  6447.         []
  6448.         [ 4096 4201 ]  % 12-bit codewords
  6449.     ] def
  6450.     /cws cws ncws cws length sub rsparams bpcw get {} forall rscodes def
  6451.     format (full) eq {
  6452.         /databits layers layers mul 16 mul layers 112 mul add string def 
  6453.     } {
  6454.         /databits layers layers mul 16 mul layers 88 mul add string def 
  6455.     } ifelse
  6456.     0 1 databits length 1 sub {databits exch (0) putinterval} for
  6457.     0 1 ncws 1 sub { 
  6458.         /i exch def
  6459.         databits cws i get 2 bpcw string cvrs 
  6460.         dup length bpcw exch sub bpcw i mul add databits length ncws bpcw mul sub add 
  6461.         exch putinterval 
  6462.     } for
  6463.  
  6464.     % Move to a point in the cartesian plane centered on the bullseye
  6465.     /cmv {size mul sub mid add} bind def
  6466.  
  6467.     % Move to a bit position within a layer
  6468.     /lmv {
  6469.         /lbit exch def
  6470.         /llyr exch def
  6471.         /lwid fw llyr 4 mul add def
  6472.         /ldir lbit 2 idiv lwid idiv def
  6473.         ldir 0 eq {  % Top
  6474.             lwid 1 sub 2 idiv neg 1 add lbit 2 idiv lwid mod add 
  6475.             fw 1 sub 2 idiv llyr 2 mul add lbit 2 mod add
  6476.             cmv
  6477.         } if
  6478.         ldir 1 eq {  % Right
  6479.             fw 2 idiv llyr 2 mul add lbit 2 mod add
  6480.             lwid 1 sub 2 idiv 1 sub lbit 2 idiv lwid mod sub
  6481.             cmv
  6482.         } if
  6483.         ldir 2 eq {  % Bottom
  6484.             lwid 2 idiv neg 1 add lbit 2 idiv lwid mod add neg
  6485.             fw 2 idiv llyr 2 mul add lbit 2 mod add neg
  6486.             cmv
  6487.         } if
  6488.         ldir 3 eq {  % Left
  6489.             fw 1 sub 2 idiv llyr 2 mul add lbit 2 mod add neg
  6490.             lwid 2 idiv 1 sub lbit 2 idiv lwid mod sub neg
  6491.             cmv
  6492.         } if
  6493.     } bind def
  6494.  
  6495.     % Create the pixel map
  6496.     % For full symbols we disregard the reference grid at this stage
  6497.     format (full) eq {/fw 12 def} {/fw 9 def} ifelse
  6498.     /size fw layers 4 mul add 2 add def 
  6499.     /pixs [size size mul {-1} repeat] def
  6500.     /mid size 1 sub 2 idiv size mul size 1 sub 2 idiv add def
  6501.  
  6502.     % Data layers
  6503.     /i 0 def
  6504.     1 1 layers {
  6505.         /layer exch def
  6506.         0 1 fw layer 4 mul add 8 mul 1 sub {
  6507.             /pos exch def
  6508.             pixs layer pos lmv databits databits length i sub 1 sub get 48 sub put
  6509.             /i i 1 add def
  6510.         } for
  6511.     } for
  6512.  
  6513.     % For full symbols expand the pixel map by inserting the reference grid
  6514.     format (full) eq {
  6515.         /fw 13 def
  6516.         /size fw layers 4 mul add 2 add layers 10.5 add 7.5 div 1 sub cvi 2 mul add def
  6517.         /mid size size mul 2 idiv def
  6518.         /npixs [size size mul {-2} repeat] def
  6519.         0 16 size 2 idiv {
  6520.             /i exch def
  6521.             0 1 size 1 sub {
  6522.                 /j exch def
  6523.                 npixs size 2 idiv neg j add i cmv     [size 2 idiv j add i add 1 add 2 mod] putinterval
  6524.                 npixs size 2 idiv neg j add i neg cmv [size 2 idiv j add i add 1 add 2 mod] putinterval
  6525.                 npixs i size 2 idiv neg j add cmv     [size 2 idiv j add i add 1 add 2 mod] putinterval
  6526.                 npixs i neg size 2 idiv neg j add cmv [size 2 idiv j add i add 1 add 2 mod] putinterval
  6527.             } for
  6528.         } for 
  6529.         /j 0 def
  6530.         0 1 npixs length 1 sub {
  6531.             /i exch def
  6532.             npixs i get -2 eq {
  6533.                 npixs i pixs j get put
  6534.                 /j j 1 add def
  6535.             } if
  6536.         } for
  6537.         /pixs npixs def
  6538.     } if
  6539.  
  6540.     % Finder pattern
  6541.     /fw fw 2 idiv def
  6542.     fw neg 1 fw {
  6543.         /i exch def
  6544.         fw neg 1 fw {
  6545.             /j exch def
  6546.             pixs i j cmv
  6547.             i abs j abs gt {i abs} {j abs} ifelse 1 add 2 mod
  6548.             put
  6549.         } for
  6550.     } for
  6551.  
  6552.     % Orientation bits
  6553.     [ [ fw 1 add neg   fw             1 ] [ fw 1 add neg   fw 1 add       1 ]
  6554.       [ fw neg         fw 1 add       1 ] [ fw 1 add       fw 1 add       1 ]
  6555.       [ fw 1 add       fw             1 ] [ fw 1 add       fw neg         1 ]
  6556.       [ fw             fw 1 add       0 ] [ fw 1 add       fw 1 add neg   0 ]
  6557.       [ fw             fw 1 add neg   0 ] [ fw neg         fw 1 add neg   0 ]
  6558.       [ fw 1 add neg   fw 1 add neg   0 ] [ fw 1 add neg   fw neg         0 ]
  6559.     ] {pixs exch {} forall 3 1 roll cmv exch put} forall
  6560.  
  6561.     % Mode ring
  6562.     format (full) eq {
  6563.         /modemap [ 
  6564.             [-5  7] [-4  7] [-3  7] [-2  7] [-1  7] [ 1  7] [ 2  7] [ 3  7] [ 4  7] [ 5  7]
  6565.             [ 7  5] [ 7  4] [ 7  3] [ 7  2] [ 7  1] [ 7 -1] [ 7 -2] [ 7 -3] [ 7 -4] [ 7 -5]
  6566.             [ 5 -7] [ 4 -7] [ 3 -7] [ 2 -7] [ 1 -7] [-1 -7] [-2 -7] [-3 -7] [-4 -7] [-5 -7]
  6567.             [-7 -5] [-7 -4] [-7 -3] [-7 -2] [-7 -1] [-7  1] [-7  2] [-7  3] [-7  4] [-7  5]
  6568.         ] def
  6569.     } {
  6570.         /modemap [
  6571.             [-3  5] [-2  5] [-1  5] [ 0  5] [ 1  5] [ 2  5] [ 3  5]
  6572.             [ 5  3] [ 5  2] [ 5  1] [ 5  0] [ 5 -1] [ 5 -2] [ 5 -3]
  6573.             [ 3 -5] [ 2 -5] [ 1 -5] [ 0 -5] [-1 -5] [-2 -5] [-3 -5]
  6574.             [-5 -3] [-5 -2] [-5 -1] [-5  0] [-5  1] [-5  2] [-5  3]
  6575.         ] def
  6576.     } ifelse
  6577.     0 1 modemap length 1 sub {
  6578.         /i exch def
  6579.         pixs modemap i get {} forall cmv modebits i get 48 sub put
  6580.     } for
  6581.  
  6582.     <<
  6583.     /ren (renmatrix)
  6584.     /pixs pixs
  6585.     /pixx size
  6586.     /pixy size
  6587.     /height size 2 mul 72 div
  6588.     /width size 2 mul 72 div
  6589.     /opt options
  6590.     >>
  6591.  
  6592.     dontdraw not {//renmatrix exec} if
  6593.  
  6594.     end
  6595.  
  6596. } bind def
  6597. % --END ENCODER azteccode--
  6598.  
  6599. % --END TEMPLATE--
  6600.